1. Home
  2. Blog
  3. Interview preparation

System design interview: how to structure your answer

How to approach a system design interview: requirements, load estimation, API, data, fault tolerance and trade-offs. A worked example and questions for practice.

Get Offer editorial team12 min read

In a system design interview, the key is to connect the requirements to how the service is built and to explain what you pay for the properties you choose. The same product can be designed in different ways if the load, acceptable data loss or deletion requirements change. Let’s walk through a URL shortener: it takes a long address, issues a short key and redirects visitors. All figures below are assumptions for the exercise, not statistics or Get Offer’s architecture.

Pin down the requirements and the scope

Core operations: create a link, open it, and disable or delete a link you own. For the first version, assume authenticated creation and public redirects by key. The required minimum doesn’t include custom domains, arbitrary aliases, precise geographic analytics or editing the destination. If the interviewer considers one of these features mandatory, you need to revisit the data model and caching rules rather than add it at the end as one more arrow on the diagram.

Clarify the properties right away: a create request must not report success while the record can still be lost beyond what the agreed recovery allows; redirects must stay fast under a large volume of reads; disabled links must not live in the cache indefinitely. Agree on specific p95 targets, availability and recovery time with the interviewer. They don’t follow automatically from the words “high load.” For this exercise, rank creation, redirects and statistics collection by importance.

  • Are only HTTP and HTTPS destinations allowed?
  • Do links need an expiration date, and can the original URL be changed?
  • What does deletion mean: hiding the link or physically removing the data?
  • Must blocking take effect immediately?
  • Do you need exact statistics for every redirect, or are approximate numbers enough?
  • How much data loss and downtime are acceptable if a region fails?

Estimate the load from the given numbers

Assume 1 million new links and 100 million redirects per day. A day has 86,400 seconds. The average creation rate is 1,000,000 / 86,400, or about 11.6 writes per second. The average redirect rate is 100,000,000 / 86,400, about 1,157.4 requests per second. The ratio of reads to creations is 100:1. That ratio is what justifies a separate discussion of the read path and the cache.

An average doesn’t determine the peak. Introduce a separate assumption for the exercise: peak load is ten times the average for both operations. That gives about 116 creations and 11,574 redirects per second after rounding up. This is a hypothesis for the calculation; in a real service, you replace it with observed data. You can’t derive the number of application instances from these RPS figures alone: you need measurements of processing time, resource usage and how dependencies behave.

Metric

Calculation

Estimate for the exercise

Average creations

1,000,000 / 86,400

11.6 per second

Average redirects

100,000,000 / 86,400

1,157.4 per second

Peak redirects

100,000,000 / 86,400 × 10

11,574 per second, rounded up

New records per year

1,000,000 × 365

365 million

Raw data per year

365 million × 300 bytes

109.5 GB in decimal units

The 300 bytes per record estimate is another explicit assumption: an average URL, the key and service fields. Long URLs can increase it. With three full copies, the raw data takes 328.5 GB, but that’s not the disk size to buy. Indexes, row versions, logs, backups and free-space headroom are calculated separately. A 365-day year was chosen for the exercise; the retention period can change the result dramatically.

Describe the API and the observable results

POST /links accepts the original URL, an optional expiration time and an idempotency key. The owner is determined from the verified session, not from an arbitrary request field. Once the record is committed, the server returns 201 and the short URL. Repeating the request with the same key and the same body returns the original result; the same key with a different body requires an explicit error, such as 409. This protects against creating several links after a network timeout.

GET /r/{key} finds the active record and returns a redirect with a Location header. For our example service, we choose a temporary 302 redirect and Cache-Control: no-store on the response to the browser: this makes it easier to manage blocking and policy changes. Public permanent caching with 301 would require different guarantees. An unknown key returns 404. An expired link can also return 404 if we don’t want to reveal that it ever existed.

DELETE /links/{key} checks the owner and marks the record as disabled. A repeated delete must not accidentally create a new link or fail because the operation has already been done. The API should distinguish validation errors, lack of access, rate limiting and temporary unavailability. A “try again” response without a stable code makes it hard for the client to choose between fixing the input and safely retrying.

Choose the data model and how keys are issued

A minimal record contains key, destination, owner_id, created_at, expires_at and disabled_at. The primary key guarantees that key is unique. An index on owner_id and created_at is useful for listing a user’s links; it isn’t needed for the redirect itself. Idempotency keys can be stored separately with the owner, a hash of the request and the result. The unique constraint must match the scope of the key: usually the owner plus the request key.

Consider a random key of eight characters from a 62-character alphabet. The key space contains 62 to the eighth power, or 218,340,105,584,896 combinations. A large number doesn’t rule out collisions. Generate a candidate with a cryptographically secure generator, try to insert the record and, if the uniqueness constraint is violated, retry with a new key. A “SELECT first, then INSERT” check without a database constraint doesn’t protect against two simultaneous creations.

The alternative is a sequential numeric ID encoded in base62. Uniqueness is then easier to guarantee, but URLs become predictable, and handing out ID ranges needs a separate solution when writes are distributed. A hash of the full URL isn’t always convenient: the same destination can belong to different owners and have different expiration dates. In the interview, pick one option, explain the trade-off and don’t present key length as an access security property.

Separate the write path from the hot redirect path

Creating a link commits it to PostgreSQL. A redirect reads the cache and falls back to the database on a miss. Redirect events go to a separate analytics queue.
Example diagram: confirming a creation depends on the database; optional redirect analytics is processed separately.

A load balancer distributes requests across application instances that keep no local user state. The create handler validates the input, reserves a key and commits the transaction to the primary database. Only then does it respond to the client. If the network drops after the commit, the client recovers the result through idempotency. If writing to the cache fails, creation can still succeed: the database remains the source of truth, and the first redirect will populate the cache.

The redirect handler uses cache-aside: it reads Redis, on a miss loads the active record from the database and caches the result for a limited time. The TTL must not extend past expires_at. For popular keys, it helps to limit concurrent loads and add a small random spread to the TTL so that many instances don’t hit the database at once. Caching missing keys can reduce the load from key enumeration, but it requires a short TTL and a memory limit.

Don’t make an exact synchronous analytics write a mandatory step of every redirect without a product requirement. The event can be sent to a queue and processed separately. This creates a new agreement: is it acceptable to lose an event if the queue fails? If not, you’ll need durable intermediate storage, which adds latency and cost to the read path. The answer depends on whether this is approximate product analytics or a pay-per-click contract.

Deleting a record from the database doesn’t by itself remove the old entry from Redis. For the first version, you can agree on a propagation window for disabling, for example up to 60 seconds, and cap the TTL at that window; on a successful delete, also invalidate the key. If the requirement is immediate blocking, a TTL alone isn’t enough. You need a path that checks the current block, or confirmed invalidation of every place that serves reads. You can’t promise strict instant blocking and uncontrolled serving of stale cache at the same time.

If Redis goes down, the application can read from the database, but that doesn’t mean the database can handle all the peak traffic. Verify this mode with a load test, limit request concurrency and set short timeouts. If a dependency can’t cope, a controlled 503 error is better than an endlessly growing in-memory queue. For popular links, a bounded local cache reduces the pressure but adds one more place from which disabled records must be removed.

Database replicas help spread reads, but replication lag can make a newly created link temporarily invisible. Possible solutions: a short read from the primary after a miss, populating the cache after commit, or an explicit eventual consistency contract. Check each option for race conditions. Primary failover requires a separate discussion of write acknowledgment and acceptable data loss: having a replica doesn’t prove a zero RPO.

Add security, observability and a growth plan

Allow only expected URL schemes and reject malformed addresses. If the service only returns Location, it doesn’t need to fetch the destination’s content. Adding previews or page checks introduces the risk of server-side requests to internal addresses and requires separate protection. Plan for creation limits, an abuse reporting mechanism and disabling malicious links. A short random key doesn’t replace authorization for private content.

Monitor p50/p95/p99 redirect latency, error rate, cache miss rate, database query time, the number of key generation retries and queue lag. For business analytics, separate real redirects from uptime checks and bots as far as the agreed methodology allows. Logs don’t need to store the full URL with personal parameters; use the key and a technical request ID, and respect retention periods.

Start with a design you can verify: several application instances, PostgreSQL, a bounded cache and observability. Add sharding and multiple regions when you hit a measured limit or face a direct requirement. End your answer with a list of unknowns: the peak profile, how popularity is distributed across keys, the retention period, blocking requirements and analytics accuracy. Such a list shows which data would actually change the architecture.

How to check the calculations and prepare your answer

  1. Recalculate the average rates from the daily numbers and label the peak factor separately.
  2. Explain which costs are not included in the 109.5 GB estimate.
  3. Walk through creation and a redirect on the diagram, naming the source of truth.
  4. Simulate a key collision, a timeout after commit and Redis being unavailable.
  5. Pick one requirement to change, such as instant blocking, and show how it affects reads.

You can check unique constraints and foreign keys against the PostgreSQL documentation. The documentation confirms the properties of a specific mechanism; target latencies and whether the chosen resources are sufficient are confirmed by testing your implementation. In a practice answer, keep these two kinds of evidence clearly apart.

Further reading