All articles

System Design in 12 Lines: The Fix for Every Common Scaling Problem

Slow reads, write spikes, failing services, duplicate requests: 12 system design symptoms, the standard fix for each, and the trade-offs interviewers ask about.

0 · log in to like, save & follow Share on LinkedIn Share on X

Most system design interviews, and most real production incidents, come down to a small set of recurring problems. Once you can name the symptom, the standard fix is usually obvious. The hard part is knowing why the fix works and what it costs you.

System Design in 12 Lines: The Fix for Every Common Scaling Problem

Here are twelve symptoms, the fix each one calls for, and the trade-offs an interviewer (or your on-call self at 2 AM) will ask about.

Symptom Fix
Slow reads Add a cache
Write spikes Buffer with a queue
Too much traffic Add a load balancer
Read-heavy database Add read replicas
Write-heavy database Shard the data
Slow queries Add indexes
Slow file loads Object storage + CDN
Temporary failures Retry with backoff
Too many requests Rate limiting
One service failing Circuit breaker
Duplicate requests Idempotency keys
Can't see what broke Logs, metrics, tracing

Let's go through them one by one.

1. Slow reads → Add a cache

The symptom: the same data is read again and again (a product page, a user profile, a config value), and every read goes all the way to the database.

The fix: keep a copy of hot data in memory, in Redis, Memcached or an in-process cache. The most common pattern is cache-aside: the application checks the cache first, and on a miss it reads the database and writes the result into the cache with a TTL.

read(key):
    value = cache.get(key)
    if value is missing:
        value = db.query(key)
        cache.set(key, value, ttl = 5 minutes)
    return value

The trade-off: a cache gives you speed and costs you freshness. You now have two copies of the truth. Decide how stale data is allowed to be, invalidate on writes where it matters, and watch out for a cache stampede: when a popular key expires, thousands of requests miss at once and hit the database together. Request coalescing or a short lock around the refill fixes that.

Practise it: Distributed Cache (Redis-like).

2. Write spikes → Buffer with a queue

The symptom: traffic is bursty. A flash sale, a viral post or a nightly import sends ten times the normal writes, and the database falls over.

The fix: put a message queue (Kafka, RabbitMQ, SQS) between the API and the slow work. The API accepts the request, drops a message on the queue and returns quickly. Workers drain the queue at a pace the database can handle.

The trade-off: the work becomes asynchronous. The user gets "we've received your order" instead of "your order is complete", so the product has to be designed for that. You also need to handle messages that fail repeatedly (a dead-letter queue) and accept that most queues deliver at least once, which leads straight to fix #11.

Practise it: Distributed Queue (RabbitMQ) and Distributed Stream (Kafka-like).

3. Too much traffic → Add a load balancer

The symptom: one server can't keep up, and when it goes down, everything goes down.

The fix: run several identical copies of the application behind a load balancer (Nginx, HAProxy, a cloud ALB). It spreads requests across healthy instances and takes failed ones out of rotation using health checks.

The trade-off: this only works if your servers are stateless. Session data, uploaded files and in-memory counters must live somewhere shared (a cache, a database, object storage), or users will be logged out when the next request lands on a different server. Algorithms matter less than people think: round robin or least-connections covers most cases.

4. Read-heavy database → Add read replicas

The symptom: the database CPU is busy serving reads, while writes are a small fraction of traffic. Most web apps look like this, often 90% reads.

The fix: add read replicas, copies of the primary that receive its changes through replication. Writes go to the primary; reads are spread across the replicas.

The trade-off: replication lag. A user updates their profile, the next page load reads from a replica that hasn't caught up, and their change seems to have vanished. The usual fix is read-your-own-writes: send a user's reads to the primary for a short time after they write.

5. Write-heavy database → Shard the data

The symptom: a single primary can no longer absorb the writes, or the data simply doesn't fit on one machine.

The fix: shard the data: split it across several databases by a shard key, for example user_id. Each shard holds a slice of the data and takes a slice of the writes.

The trade-off: sharding is the most expensive fix on this list, so do it last. Choose the key carefully: a bad key creates hot shards (one celebrity account on a single shard). Queries that span shards, joins and transactions across shards all become hard. Consistent hashing helps you add shards later without moving everything.

Practise it: Key-Value Store (Dynamo-like).

6. Slow queries → Add indexes

The symptom: a query that was fast with 1,000 rows takes seconds with 10 million, because the database scans the whole table.

The fix: add an index on the columns you filter, join and sort by. Use EXPLAIN (or EXPLAIN ANALYZE in PostgreSQL) to confirm the query actually uses it. For multi-column filters, a composite index in the right column order often beats several single-column ones.

The trade-off: every index speeds up reads and slows down writes, because each insert and update must also update the index. Indexes also take disk and memory. Index what your real queries need, not every column "just in case". This is the cheapest fix on the list, so try it before reaching for caches, replicas or shards.

7. Slow file loads → Object storage + CDN

The symptom: images, videos and downloads are served from your application servers, which eat bandwidth and are slow for users far away.

The fix: store files in object storage (Amazon S3, Azure Blob, DigitalOcean Spaces) and serve them through a CDN. The CDN caches copies at edge locations close to users, so a user in Mumbai gets the file from Mumbai rather than from your server in Frankfurt.

The trade-off: caching at the edge means invalidation is now your problem. The common trick is versioned file names (logo.v42.png): a new version gets a new URL, so you never need to purge. Use signed URLs for private files.

Practise it: Google Drive / Dropbox and YouTube Video Ingestion.

8. Temporary failures → Retry with backoff

The symptom: network blips, a briefly overloaded dependency or a database failover cause random failures that would succeed a second later.

The fix: retry, but with exponential backoff and jitter: wait 100 ms, then 200 ms, then 400 ms, each with a random offset, and give up after a few attempts.

for attempt in 1..5:
    try: return call()
    except TransientError:
        sleep(random(0, 100ms * 2^attempt))
raise

The trade-off: naive retries can make an outage worse. If every client retries immediately, a struggling service gets hit with two or three times its normal load: a retry storm. Jitter spreads the retries out. Retry only errors that can succeed later (timeouts, 503s), never a 400, and only for operations that are safe to repeat (see #11).

9. Too many requests → Rate limiting

The symptom: one client, whether a buggy script, a scraper or an attacker, sends so many requests that everyone else suffers.

The fix: rate limit per user, API key or IP. The token bucket algorithm is the classic choice: each client has a bucket that refills at a fixed rate, every request takes a token, and an empty bucket means 429 Too Many Requests. It allows short bursts while capping the average rate.

The trade-off: with many servers, the counters must be shared (usually in Redis), which adds a network call per request. Return a Retry-After header so well-behaved clients know when to come back, and set limits per endpoint: login and OTP endpoints deserve much tighter limits than read-only pages.

Practise it: API Rate Limiter and Ticketmaster Queue System.

10. One service failing → Circuit breaker

The symptom: a downstream service (payments, search, recommendations) becomes slow. Your threads all wait on it, and soon your service is down too. One failure cascades through the whole system.

The fix: wrap calls in a circuit breaker. It has three states:

  • Closed: calls flow normally while failures are counted.
  • Open: after too many failures, calls fail immediately without even trying, which gives the dependency time to recover.
  • Half-open: after a cool-down, a few trial calls go through. If they succeed, the breaker closes again.

The trade-off: when the breaker is open you need a fallback: cached results, a default value, or a graceful "recommendations unavailable" instead of an error page. Pair it with timeouts on every remote call; a breaker can't help if a call waits forever.

11. Duplicate requests → Idempotency keys

The symptom: a user double-clicks "Pay", a mobile client retries after a timeout, or a queue redelivers a message, and the customer is charged twice.

The fix: the client sends a unique idempotency key with the request (say, a UUID per checkout attempt). The server stores the key with the result. If the same key arrives again, it returns the stored result instead of doing the work twice.

The trade-off: you need storage for keys, with an expiry, and you must handle two copies arriving at the same time. A unique constraint on the key in the database is the simplest reliable lock. This is non-negotiable for anything involving money, and it's what makes the retries from #8 and the queues from #2 safe.

Practise it: Credit Card Processing, Wire Transfer API and Payment Gateway Integration.

12. Can't see what broke → Logs, metrics, tracing

The symptom: users report that "the site is slow", and you have no idea which of your twelve services is responsible.

The fix: the three pillars of observability:

  • Logs tell you what happened in one place. Make them structured (JSON) and include a request ID.
  • Metrics tell you how much and how often: request rate, error rate, latency percentiles (p50, p95, p99), queue depth. Alert on these.
  • Traces tell you where the time went across services: a single request followed through the API, the cache, the queue and the database.

The trade-off: observability costs money and storage, and high-cardinality labels (one metric per user ID) can blow up a metrics system. Sample traces, keep log retention sensible, and alert on symptoms users feel (errors, latency) rather than on every CPU spike.

Practise it: Distributed Tracing, Metrics Monitoring (Prometheus) and Distributed Metrics Logging.

How to use this list in an interview

The twelve lines are a vocabulary, not a design. A strong answer:

  1. Starts simple. One server and one database. Don't open with sharding.
  2. Finds the bottleneck with numbers. "100 million reads a day is about 1,200 per second, and 20,000 at peak, so reads are the problem."
  3. Applies the cheapest fix first. Indexes before caches, caches before replicas, replicas before shards.
  4. Names the trade-off out loud. "A cache adds staleness. For a product price that's fine for 60 seconds; for an account balance it isn't."

Notice how the fixes connect. Queues (#2) need idempotency (#11). Retries (#8) need circuit breakers (#10) so they don't become retry storms. Caches (#1) and CDNs (#7) both raise the same invalidation question. Interviewers love these connections, because they show you understand the system rather than memorising a list.

Practise on real problems

Reading the list is the easy part. Applying it to a real problem is the skill. GeeksArray has 63 system design challenges with written walkthroughs and diagrams, from an API Rate Limiter to WhatsApp Messaging and a ChatGPT/LLM Backend. Pick one, sketch your design first, then compare it with the walkthrough and count how many of these twelve fixes you used.

Enjoyed this article? Get the best GeeksArray articles in your inbox — once a week, no spam, unsubscribe anytime.

Comments (0)

Log in to join the conversation.

No comments yet — be the first to share your thoughts.