KatInterview

Highly Available Order Service With Durable Async Jobs

System DesignModel answer
MediumModel answerSystem Designspring-boothigh-availabilitymessage-queue

Last updated

Design a horizontally scalable Spring Boot order backend that survives deploys and traffic spikes while guaranteeing that invoice and email jobs are never lost.

Scenario

Your team runs an order-processing backend built with Spring Boot. At peak it must absorb about 5,000 requests per second. Each new order also triggers slow follow-up work, such as rendering a PDF invoice and sending one or more confirmation emails.

The service has to stay up while new versions are released, cope with sudden bursts of traffic, and never silently drop a follow-up job, even if a server dies halfway through one.

What your design must cover

  1. Statelessness and scaling. Make the application tier horizontally scalable behind a load balancer.
  2. Authentication state. Explain how a logged-in user is recognised no matter which instance handles the request.
  3. Offloading slow work. Describe how long-running jobs leave the request-response path.
  4. Crash safety. Show how jobs survive the failure of an instance in the middle of processing.
  5. Zero-downtime releases. Explain how you ship a new version without cutting off in-flight requests.

Expected deliverables

  • A high-level description or diagram of the path between the client, load balancer, Spring Boot instances, database, and job queue.
  • The specific technologies or Spring features you would use for shared authentication state and for asynchronous messaging.
  • A comparison of queueing approaches, for example a durable message broker versus a database table that workers poll, with the trade-offs of each.

State your assumptions about traffic mix, latency targets, and job cost, and use them to size the system.

Hints

Hint 1

Convert the headline number into capacity: how many API instances and how many CPU-seconds of invoice rendering per second? That should show the web tier and the job workers need to scale separately.

Hint 2

There are three distinct ways to lose a job: the app crashes between saving the order and publishing the message, the broker loses the message, and a worker dies mid-task. Match each failure with its own remedy.

Hint 3

Because retries and redelivery produce at-least-once delivery, think about what makes a consumer safe to run twice on the same message, and what you do with messages that keep failing.

Hint 4

For deployments, think about readiness probes, connection draining, graceful shutdown, and keeping database schema changes compatible with both the old and new application versions.