Queues and async processing: background jobs and event-driven systems
Why not everything should happen while the user waits, how queues and events decouple systems, and the product implications of "eventually".
On this page
Some work must happen while the user waits; most doesn't. Sending emails, generating invoices, resizing photos, notifying a restaurant, updating analytics: these can happen in the background. Queues and event-driven design make products faster and more resilient, at the cost of "eventual" rather than instant results. That cost is a product decision.
Why interviewers ask this
System design questions almost always have a synchronous part (the user action) and an asynchronous part (everything that follows). Interviewers want to see you separate them, understand why queues help with spikes and failures, and think about the user experience when things happen later or fail silently.
The framework
1. Synchronous vs asynchronous
- Synchronous: the user waits for the result (logging in, placing an order, getting a search result).
- Asynchronous: the work is accepted now and done later (sending a receipt email, generating a PDF, recalculating recommendations).
Rule of thumb: keep the synchronous path short, only what the user truly needs to see, and push the rest to the background.
2. Queues and background jobs
A message queue is a to-do list between services. One service drops a task in; workers pick tasks off and process them.
flowchart LR
A["Order service"] -->|order placed| Q[["Queue"]]
Q --> W1["Worker: send receipt"]
Q --> W2["Worker: notify restaurant"]
Q --> W3["Worker: update analytics"]
W1 -.->|fails| RT["Retry with backoff"]
RT -.->|still fails| DLQ[["Dead-letter queue"]]Benefits:
- Speed: the user isn't waiting for slow work.
- Absorbing spikes: a flash sale creates a backlog that workers chew through, instead of crashing the system.
- Resilience: if the email provider is down, jobs wait and retry instead of failing the order.
3. Event-driven systems
Instead of the order service calling every other service directly, it publishes an event ("order placed"), and any service that cares subscribes. New features (a loyalty-points service) can listen without changing the order service. The tradeoff: flows are harder to trace and debug.
4. What PMs must think about
- User expectations: show progress ("Your report is being prepared, we'll email you"), not a frozen screen.
- Ordering and duplicates: messages can arrive twice or out of order, so processing must be idempotent (sending the same notification twice shouldn't double-charge or double-notify).
- Failures: what happens after retries run out? A dead-letter queue and an alert, plus a plan for the user.
- Delays: if the queue backs up, how late is acceptable? Monitor queue length and age of the oldest message.
Worked example
Question: "Users can export a year of transaction history as a PDF, but big exports time out and fail. How would you fix it?"
Sample answer:
"The problem is that we generate the PDF synchronously, while the user waits, and big exports take longer than the request timeout.
Proposed design:
- When the user taps Export, we create an 'export job', put it on a queue, and immediately respond with 'We're preparing your export. We'll notify you when it's ready (usually under 2 minutes).'
- A background worker generates the PDF, stores it securely, and marks the job done.
- We notify the user in-app and by email with a download link that expires after a few days, since it contains financial data.
- The export screen shows status: preparing, ready, or failed with a retry button.
Edge cases: if generation fails, retry automatically a few times, then show 'failed' with an option to retry, and alert engineering if failures spike. If a user taps Export twice, we reuse the existing job instead of creating duplicates.
Metrics: export success rate, time to ready (p95), and support tickets about exports. I'd also check whether small exports could still be instant, to keep the fast path for the common case."
Common mistakes
- Doing slow work while the user waits.
- Hiding async status, so users think nothing happened and retry repeatedly.
- Ignoring duplicates and retries, causing double emails or charges.
- No plan for permanent failures.
- Using async where the user needs an immediate, guaranteed answer (payment confirmation).
Interviewer tips
What "great" sounds like:
- "What does the user need to see right now? Everything else goes to a queue."
- "Queues absorb spikes: a backlog is better than an outage."
- "Workers must be idempotent, because messages can be delivered twice."
- "We'd show clear status so users don't keep retrying."
- "I'd monitor queue depth and the age of the oldest message."
Practice questions
Answer one in a mock interview and get graded instantly.
1.Big PDF exports time out and fail. How would you redesign the feature?
Practice this →2.Explain what happens when a user taps "Place Order" in a food delivery app, separating what happens immediately from what happens later.
Practice this →3.When would you not use asynchronous processing?
Practice this →
Finished reading?
