Skip to content
Laviyx Learn

Try

System Design Interview Questions

Frequently asked system design interview questions on scaling, load balancing, caching, databases, replication, sharding, queues, consistency and classic designs, with hints and answers.

20 questions · Updated

  1. 1.What is the difference between vertical and horizontal scaling?

    BeginnerConceptScaling
    Show hint

    Bigger, or more?

    Show solution

    Vertical scaling uses a bigger machine, and it has a limit. Horizontal scaling adds more machines, which needs stateless servers, but it scales further and adds redundancy.

  2. 2.Why do you need a load balancer?

    BeginnerConceptBuilding blocks
    Show hint

    Spread and protect.

    Show solution

    It spreads traffic across servers, removes unhealthy ones, and lets you add or replace servers without clients noticing.

  3. 3.How do you choose between SQL and NoSQL?

    BeginnerConceptDatabases
    Show hint

    Start from the access pattern.

    Show solution

    Use relational databases when you need transactions, joins or flexible queries. Choose NoSQL for a specific pattern, such as very high write volume or simple key lookups.

  4. 4.10 million daily users each make 20 requests. What is the average and peak QPS?

    BeginnerCodingEstimation
    Show hint

    Divide by seconds in a day.

    Show solution

    200 million a day, divided by 86,400, is about 2,300 a second. Peak at three times that is about 7,000 a second.

  5. 5.What does a stateless server mean, and why does it matter?

    BeginnerConceptScaling
    Show hint

    Could any server handle the next request?

    Show solution

    It keeps no user data between requests, so that any server can handle any request. This allows horizontal scaling and easy replacement. Sessions go in shared storage.

  6. 6.Explain cache-aside.

    BeginnerConceptCaching
    Show hint

    Who fills the cache?

    Show solution

    The app checks the cache first. On a miss, it reads the database and stores the result. On a write, it updates the database, and deletes the cache entry.

  7. 7.Explain the CAP theorem.

    IntermediateConceptConsistency
    Show hint

    What must you choose during a partition?

    Show solution

    When a network partition happens, a distributed store must choose between consistency and availability. Since partitions cannot be avoided, that is the real choice.

  8. 8.What problem does consistent hashing solve?

    IntermediateConceptSharding
    Show hint

    Compare with hash modulo N.

    Show solution

    With hash % N, changing N moves most keys. Consistent hashing places keys and servers on a ring, so that adding a server moves only a small share.

  9. 9.Why do read replicas not help with write load?

    IntermediateConceptDatabases
    Show hint

    What does each replica do with a write?

    Show solution

    Every replica must apply every write, so they add read capacity only. Write load needs sharding, batching or queues.

  10. 10.What is a cache stampede?

    IntermediateDebuggingCaching
    Show hint

    A popular key expires.

    Show solution

    A popular entry expires, and many requests hit the database together. Use a lock so that one request refills it, or refresh entries before they expire.

  11. 11.How do you stop a payment being charged twice on retry?

    IntermediateDesignAPIs
    Show hint

    A key sent by the client.

    Show solution

    The client sends an idempotency key, and the server stores the result under that key. A retry with the same key returns the stored result.

  12. 12.A request takes 10 seconds because it generates a report. How do you improve it?

    IntermediateDesignQueues
    Show hint

    The user need not wait.

    Show solution

    Put the job on a queue, and return a job ID at once. A worker builds the report, and the client polls for it, or gets a notification.

  13. 13.Design a rate limiter for an API.

    IntermediateDesignBuilding blocks
    Show hint

    Algorithm, storage, location.

    Show solution

    Use a token bucket in Redis with atomic operations, at the API gateway, keyed by user or API key. Return 429 with Retry-After, and decide whether to fail open if Redis is down.

  14. 14.Design a URL shortener.

    IntermediateDesignCase studies
    Show hint

    Read-heavy, with short codes.

    Show solution

    Generate 7-character base62 codes from block-allocated IDs. Store code and URL in a database, and cache popular links in Redis. Redirect with 302 if you need analytics, and send click events to a queue.

  15. 15.How do you design a news feed for accounts with millions of followers?

    AdvancedDesignCase studies
    Show hint

    Fan-out on write fails for celebrities.

    Show solution

    Use a hybrid. Fan out on write for normal accounts, storing post IDs in a Redis feed for each follower. Merge posts from very large accounts at read time.

  16. 16.How do you keep chat messages in order?

    AdvancedDesignCase studies
    Show hint

    Do not trust device clocks.

    Show solution

    Assign an increasing sequence number per conversation on the server. Devices sort by it, and they use gaps to detect missed messages.

  17. 17.How do you prevent two users booking the same seat?

    AdvancedDesignCase studies
    Show hint

    Check and update in one step.

    Show solution

    Use a conditional UPDATE or a row lock, so that the check and update are atomic, plus a unique constraint. Hold seats with an expiry during payment.

  18. 18.How do you keep data consistent across microservices?

    AdvancedDesignMicroservices
    Show hint

    Compensating actions.

    Show solution

    Use a saga: a chain of local transactions, with compensating actions on failure. Use the outbox pattern, so that events are published reliably.

  19. 19.How do you find nearby drivers quickly?

    AdvancedDesignCase studies
    Show hint

    Do not scan everyone.

    Show solution

    Index locations by cell, using geohash, a quadtree or a hexagon grid, and search the rider's cell and its neighbours. Keep the latest positions in memory.

  20. 20.Your site is suddenly slow. How do you investigate?

    AdvancedDebuggingOperations
    Show hint

    Follow the request.

    Show solution

    Check recent deployments, then look at p99 latency, error rates and saturation. Use traces to find the slow service, and logs to find why. Check the database, the cache hit ratio, and queue length.

Review the lessons