When your SaaS product queues an LLM job, record the organization that owns it and resolve authorization again when the worker dispatches the model request. The queue can delay a job until after a plan changes, a user leaves, or a connection is removed. The organization is a property of the job. Permissions and available routes are properties of the execution environment at the time you run it.
Define what the job carries
At enqueue time, derive the organization from authenticated application context and verify that the initiating user can perform the requested operation. Carry the application job ID, organization ID, initiating actor, operation type, deadline and an organization-scoped reference to the input. Keep the enqueue-time policy or configuration version as evidence when available. A worker can compare it with the current version when explaining why a job was refused.
AWS's multi-tenant SQS example derives tenant context from authenticated claims and makes it available to the consumer. Use the same principle with your queue. Restrict producers and check that the worker's input lookup enforces the same organization scope. Keep API keys and raw prompts out of the queue envelope. A trusted organization ID cannot establish that the object referenced by a job belongs to that organization.
Decide what the worker can run
Suppose a SaaS reporting feature queues a summary every night. An analyst also has an on-demand button for the same report. Both jobs share a worker, but the scheduled report belongs to an authorized organization-managed schedule. The on-demand report uses the initiating user's access. Make this difference explicit in the operation type and test the decisions at dispatch.
| Change while the job waits | Dispatch decision |
|---|---|
| Analyst loses access to the source | Stop the on-demand report before retrieving the source |
| Analyst who set up the schedule leaves | Run the scheduled report only if the organization-managed schedule remains authorized |
| The organization disables the previously selected model | Select another currently approved model only if the operation permits it |
| The source reference no longer resolves within the organization | Stop and record the failed input check |
| The job exceeds its deadline | Expire the job and record that no request was dispatched |
In this example, replay a queued report after removing a model and removing source access in separate tests. The first should validate the route decision. The second should show that the route selector never sees the protected data. In both cases inspect the worker trace for the organization and operation identifiers. Repeat the tests through the retry and manual replay paths because those may reconstruct the job from a different record.
Treat scheduling and enforcement as separate controls
A shared queue gives one large customer the opportunity to consume a disproportionate share of worker time. Amazon SQS fair queues use the message group ID to identify tenants and prioritize quiet tenants when a noisy neighbor dominates in-flight work. That grouping controls delivery behavior. Your worker still needs authorization, an inference limit, and a distinct outcome when the job cannot run under current policy. Track queue dwell time and provider latency separately so an operations team can locate the delay.
At dispatch, populate Alectura's organization and user headers from your server-side context. The gateway contract specifies which headers carry identity and that a missing value is null. Test the path for a missing organization and reject it in your application before the gateway call if the job requires organization context. If the provider responds with a transient error and the job is still within its deadline, the next attempt should run the same dispatch-time checks. Record earlier attempts under the same job so you can investigate uncertain outcomes and prevent a duplicate delivered report. Review the per-customer policy guide when extending this pattern from one worker to the rest of the product.
Source documents (2)
Trace a request through Alectura.
Bring a sample prompt and a customer policy. See what reaches the model and which decisions appear in the request record.