System Design Academy

Saving…

Lesson 5 of 9 in Module 40 of 54 lessons complete

Synchronous vs Asynchronous Work

Module 4, lesson 5Concept10 min

Definition

Synchronous work

In plain English
Synchronous work is done while the user waits, before the response is sent.
Think of it like
It is like waiting at the counter while your sandwich is made.

Asynchronous work

In plain English
Asynchronous work is handed off to be done later, so the response can return right away.
Think of it like
It is like dropping off dry cleaning and getting a ticket to collect it tomorrow.

Why it exists

A refill is saved, but sending its confirmation takes another 800 ms. The user waits for work they do not need immediately.

A contract PDF takes three seconds to generate. Moving that work outside the request lets the app confirm acceptance sooner.

How it works

Background job

In plain English
A background job is a task that runs outside the user's request, often on separate worker machines.
Think of it like
Like the kitchen prepping sauces before the restaurant opens.

Worker

In plain English
A worker is a process whose job is to pick up and run background jobs.
Think of it like
Like the cleaner who works through the dry-cleaning tickets.
NeedChooseExample
Required before continuingSynchronousPayment approval
Can arrive laterAsynchronousReceipt email

A user requests a refill; the API saves it and a job, publishes the job, and responds before a worker sends SMS.

Save essential work before handing off the notification.

A user requests a refill; the API saves it and a job, publishes the job, and responds before a worker sends SMS.

  1. Save the essential fact

    Store the refill and its pending notification together in one database transaction.

  2. Hand off the work

    Publish saved pending jobs to a durable waiting place and retry failed publishing.

  3. Respond honestly

    Confirm the saved refill without claiming that the SMS has arrived.

  4. Run and monitor

    Workers retry failed notifications and report jobs that remain stuck.

Writing the refill and then forgetting its notification after a crash is a real risk. Saving both together closes that gap.

Examples

Pharmacy refills

Saving the refill is synchronous. A background job sends its confirmation SMS after the response.

During a five-minute SMS outage, saved jobs wait for retries. Refills can succeed while essential storage and the handoff remain available.

Save refill and job → Confirm refill → Worker sends SMS later.

An SMS outage need not block saving a refill.

Save refill and job → Confirm refill → Worker sends SMS later.

The insight

Do the essential part now, the rest later.

Trade-offs

Pros

  • Shorter request waits.
  • Separate slow provider failures.
  • Schedule heavy work off peak.

Cons

  • Results arrive later.
  • Saved jobs need monitoring.
  • Safe handoff requires additional storage logic.

Use when

  • The result can arrive after acceptance.
  • Slow providers should not block essential work.

Avoid when

  • The next user step needs the result.
  • A tiny task needs no separate handoff.

Quick check

Which step should stay synchronous in a checkout?
The SMS provider is down for 5 minutes. With SMS sent asynchronously, what happens to refill requests?

Takeaways

  • Save essential work before responding.
  • Hand work that can wait to background workers.
  • Save pending jobs safely and monitor their completion.

Try the quick check above whenever you feel ready.

Previous: CDNs