Scrivio Interview library
ScenarioIntermediate7 min read · updated 13 November 2026

Twenty minutes into designing a URL-click analytics service, you have a design built for 5,000 events per second with a single PostgreSQL primary. The interviewer now says the real rate is 250,000 events per second with bursts of twice that.

How do you adapt the design without starting over, and how do you explain which parts survive and which change?

We restate the new numbers and redo the key estimate aloud: 250,000 events per second is about 21.6 billion a day, which one PostgreSQL primary cannot write or store as rows. We keep everything that does not depend on the write rate, such as the API, the event schema and the read paths, and change the write path: a Kafka log partitioned by short code absorbs bursts, a stream processor pre-aggregates counts per short code per minute into a write-optimised store, and raw events go to object storage for reprocessing. Then we name the new trade-offs: counts lag by seconds, hot codes need key splitting, and exactly-once counting needs idempotent or transactional aggregation.

Why this question is asked

Changing a requirement halfway through is one of the most common moves in a design interview, because it shows whether the candidate understands the design or memorised it. In real work the same thing happens when a product turns out to be fifty times more popular than planned. The worst reactions are to defend the old design or to erase the board. In this answer, we will redo the estimate, find the component that breaks first, keep what survives, redesign the write path around a log and pre-aggregation, and finish with the trade-offs the new design brings.

1Restate the Numbers and Redo the Estimate

The first thing to do is say the new number back and recompute what it means, out loud, so the interviewer sees the reasoning. 250,000 events per second times 86,400 seconds is about 21.6 billion events a day, with bursts of 500,000 per second. If each raw event row takes around 100 bytes with indexes, that is over 2 TB a day, more than 700 TB a year.

Compare that with what a single PostgreSQL primary can do. Even a large, well-tuned instance handles tens of thousands of simple inserts per second, and every insert also updates indexes and writes WAL, the write-ahead log PostgreSQL uses for durability and replication. 500,000 per second in bursts is an order of magnitude beyond that, and hundreds of terabytes a year of row data would make vacuum, backups and index maintenance unmanageable. So we can say clearly: the write path into the database breaks first, both in rate and in storage growth.

2Say What Survives

Before changing anything, we list what does not depend on the write rate. The public API for creating short links and for reading statistics stays the same. The event schema, a short code, a timestamp, a country and a referrer, stays the same. The redirect service that answers clicks stays the same; it only needs to emit events cheaply. The read path for dashboards keeps its shape, although it will now read aggregates.

Saying this explicitly matters for two reasons. It shows the interviewer that we understand which decisions were driven by which numbers. And it keeps the redesign small: we only change the part the new number broke.

3Put a Durable Log in Front of Storage

The redirect service now publishes each click to Kafka instead of writing to the database. Kafka is a durable, partitioned log: producers append events, and each partition is replicated to several brokers and kept for a set time. We partition by short code, so all clicks for one code land in the same partition in order. With, say, 64 partitions, each one carries about 4,000 events per second on average, which is comfortable for a broker.

The log decouples ingestion from storage. During a burst of 500,000 events per second, Kafka simply accumulates them, and consumers read at their own pace. If the storage layer is slow or down for a few minutes, nothing is lost; the consumers catch up from their saved offsets, the position in each partition they have processed up to.

Step throughWrite path after the change
  1. Redirect serviceAnswers clicks, publishes one event per click
  2. Kafka topic clicks64 partitions keyed by short code, replicated, kept 7 days
  3. Stream processorCounts per short code per minute, idempotent writes
  4. Aggregate storeCassandra or ClickHouse, minute rows, built for heavy writes
  5. Object storageRaw events in S3 as Parquet, for reprocessing

5 layers, from the top down. Step through them one at a time.

The API, schema and read paths above and beside this path are unchanged.

4Change What We Store

Nobody reads 21.6 billion individual rows a day. Dashboards ask 'how many clicks did this code get per hour, by country'. So a stream processor, such as Kafka Streams or Flink, reads the topic and keeps a running count per short code per minute, optionally per country. Once a minute it writes those counts. If there are 2 million active codes in a minute, that is at most 2 million aggregate rows a minute, about 33,000 writes per second, and usually far fewer because most codes get no clicks in a given minute.

Those aggregates go to a store built for heavy, mostly append-style writes, such as Cassandra, or a column store such as ClickHouse when the dashboards need flexible group-by queries. The raw events are also written in batches to S3 as compressed Parquet files. That copy is cheap, and it lets us recompute aggregates if we find a bug or need a new dimension later.

SQL
-- aggregate table, one row per code per minute
CREATE TABLE clicks_by_minute (
short_code text,
minute timestamp,
country text,
clicks counter,
PRIMARY KEY ((short_code), minute, country)
);
-- a dashboard read: one partition, a time range
SELECT minute, country, clicks FROM clicks_by_minute
WHERE short_code = 'aZ3k9' AND minute >= '2026-11-13 10:00';

One caution about the counter column in Cassandra: counter updates are not idempotent, so a retried write can count twice. If exact counts matter, we write each minute's total as a plain value keyed by (code, minute, country), so replaying the same result simply overwrites the same row. That brings us to the trade-offs.

5Name the New Trade-Offs

The new design is not free, and naming the costs is part of a strong answer. First, counts are now eventually consistent: a click appears on the dashboard after the minute closes and the processor writes it, typically within tens of seconds. We should confirm that is acceptable.

Second, hot keys. A viral short code may receive 100,000 clicks per second, and because we partition by code, all of them land on one partition and one processor task. The fix is key splitting: append a small random suffix, such as 0 to 15, to the key for codes known to be hot, count the sub-keys separately and sum them on read or in a second stage.

Third, exactly-once counting. If a processor crashes after writing counts but before saving its offsets, it will reprocess some events. We either make writes idempotent, as above, or use Kafka transactions so the output and the offsets are committed together. Kafka Streams offers this as its exactly_once_v2 processing guarantee.

6Follow-up questions

Which metric would show you that the stream processor is falling behind?

Consumer lag: for each partition, the difference between the latest offset in the topic and the offset the processor has committed. Lag that stays flat is fine; lag that grows steadily means the processor cannot keep up. It helps to express lag as time, the age of the oldest unprocessed event, because that maps directly to dashboard freshness and can be alerted on, for example when it exceeds two minutes.

Why not just shard PostgreSQL by short code?

It would fix the write rate with enough shards, perhaps 20 or more, but it would still store 21.6 billion rows a day that nobody reads individually. Pre-aggregating changes the problem itself and costs far less. Sharded PostgreSQL could still be a fine home for the aggregates if the team knows it well.

How long should Kafka keep the events?

Long enough to recover from the worst realistic outage of the consumers plus time to reprocess, often 3 to 7 days. Longer history lives in S3, which is cheaper per terabyte than broker disks.

7Conclusion

In this answer, we adapted a design to a fiftyfold increase without starting over. We redid the estimate aloud, found that the write path into one PostgreSQL primary breaks first, kept the API, schema and read paths, and rebuilt the write path around a Kafka log partitioned by short code, a stream processor that stores per-minute aggregates, and raw events in S3. We finished by naming the costs: seconds of staleness, hot-key splitting and exactly-once counting.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would restate the number and redo the estimate out loud: 250,000 events a second is about 21.6 billion a day, with bursts of half a million, and well over 2 terabytes of rows a day.

Then, if they want more

One PostgreSQL primary cannot take that write rate or that storage growth, so the write path into the database is what breaks first. Then I would say what survives: the API, the event schema, the redirect service and the shape of the read paths do not depend on the write rate, so they stay.

For the write path, the redirect service publishes each click to Kafka, partitioned by short code, so bursts are absorbed by the log and consumers write at their own pace without losing anything.

A stream processor such as Kafka Streams or Flink counts clicks per code per minute and writes those aggregates to a store built for heavy writes, like Cassandra or ClickHouse, while raw events go to S3 as Parquet for reprocessing.

Finally, I would name the trade-offs: counts are now seconds behind, a viral code needs its key split into sub-keys, and exactly-once counting needs idempotent writes or Kafka transactions. To know the processor is falling behind, I would watch consumer lag, ideally expressed as the age of the oldest unprocessed event.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How do you adapt the design without starting over, and how do you explain which parts...": https://scrivio-interview-library.netlify.app/architecture/sd-fundamentals/892fe2127b/