Video in progress

Staff 🌱 Spring

Design an order service in Spring Boot that handles 10,000 requests per second. What are the main architectural decisions?

First I pin down the requirements: the read/write ratio, peak load, consistency and latency. Then: a stateless horizontally scaled service, a short idempotent write path, heavy work asynchronous through outbox + Kafka, partitioning and caching in the database, and backpressure. I confirm every decision with a load test.

📖 Answer

  1. Requirements. Is 10k RPS an average or a peak? How much is writes (creating orders) and how much is reads (checking status)? 1k writes + 9k reads versus 10k writes are completely different designs.

  2. The service: stateless, many instances, horizontal autoscaling; Java 21 virtual threads or well-tuned pools; a timeout, circuit breaker and bulkhead on every dependency.

  3. The write path, with the synchronous part kept minimal. Validation, the idempotency key, and the order and outbox records go in one short transaction, and the response is 202 Accepted or 201. Payment, warehouse and notifications are asynchronous through events, with a saga.

  4. Database:

  • 1k INSERT/s is doable for PostgreSQL, but keep indexes minimal and use batching and short transactions;
  • time-based (monthly) partitioning, which makes archiving old data and VACUUM easier;
  • reads from replicas and the cache, with status queries from Redis;
  • if growth is large, sharding by customer id (choosing the key correctly up front is important).
  1. Backpressure: rate limiting at the gateway, monitoring Kafka consumer lag, a fast 503 when saturated instead of choking in a queue.

  2. Observability and verification: an SLO, for example p99 < 300 ms for order creation; a load test at 2x the peak with Gatling/k6 to find the saturation point; and seeing in a chaos test what happens when Kafka or a replica goes down.

In an interview, it's important to think in numbers and state the tradeoffs openly. For example, an asynchronous flow improves latency, but the user sees the order status as eventually consistent.