InterviewLegend

Design a Live Payment Count Dashboard

Frequently asked
Alex Chen24 min readGuide updated
In this lesson
  • Decide what counts as a payment and who reads the number before drawing anything
  • Grow the design from one SQL count to per-second buckets fed by an event log
  • Handle duplicates, late events, crashes and counter drift with concrete rules

Understanding the problem

The prompt

Something like this: an internal admin dashboard shows how many payments were made in the last minute. At first one person looks at it and payments trickle in. Then many people watch it and payments pour in. Design it, and keep the number trustworthy as it grows.

This is the design question that comes up most at Ramp, and it comes in two framings. In January 2026 a candidate presented a project in a round the recruiter had called a project deep dive. In the final 20 minutes, with no warning, the interviewer asked how to count visits to a website over the past minute. A September 2025 candidate got it as "How would you display the count of the latest Wikipedia posts in the last minute on a TV?" The payments framing showed up in July and August 2026, as a payment count on an internal admin dashboard. It starts with one reader and low write volume, then grows to many readers and many updates. The exact stages vary, so don't expect a fixed script. Expect the arc: small first, then bigger.

The person looking at the number decides most of this. Picture someone in payments operations watching a wall screen during a big customer launch, or an on-call engineer checking whether card payments are still flowing after a deploy. Neither of them is doing accounting. They want to know, right now, whether the number looks normal. That shapes everything after it. A count that's two seconds old and off by three is fine for them. A count that freezes and quietly reads zero is a disaster, because someone will call it an outage. Finance needs exact totals too, and it gets them from the ledger.

The Ramp angle
Ramp interviewers grade product thinking. Ask who reads this number and what they do when it changes. Then build the smallest thing that serves them, and grow it only when the prompt grows.

How to spend the time

You may get 20 minutes at the end of a deep dive or most of an hour. Plan both. In 20 minutes, aim for a clear first stage, the scaled design and one strong deep dive. With 45, add the failure cases.

PartIn 20 minutesIn 45 minutes
Who reads it, what counts3 minutes5 minutes
Stage one: one reader, few payments3 minutes5 minutes
Scaled design: event log, buckets, cache8 minutes12 minutes
Deep dives5 minutes, on duplicates and late events20 minutes, adding crashes, drift, readers and monitoring
Wrap up1 minute3 minutes
A plan for the short design question and for a full slot. Drop the wrap up before you drop the first stage.

Requirements

Functional requirements

First pin down what a payment is, since that question changes the design. A card payment can be attempted, authorized, declined, settled and refunded, and each of those can be an event. Counting every event would count one purchase two or three times. The sensible default is to count each payment once, when it's first approved, and to show declines as a separate number if anyone wants it. Say the choice out loud and let the interviewer change it. Then the window. "The last minute" here means a rolling 60 seconds that moves every second, which is different from the calendar minute that started on the hour. And it's measured by when the payment happened, which isn't always when the event reached us.

In scope

  • Show the number of approved payments in the last 60 seconds
  • Refresh it every second or two for anyone watching
  • Count each payment once, even when its event arrives twice or late
  • Show how fresh the number is, and say so when it's stale
  • A short history for a sparkline, such as the last 15 minutes

Below the line (say it, then skip)

  • Exact totals for finance, which come from the ledger
  • Breakdowns by merchant or team, unless asked (it's a follow-up)
  • Authentication for the admin tool beyond a normal login
  • Long-term analytics over months of payments

Non-functional requirements

Freshness comes first. A payment should show up in the count within about two seconds. Correctness is a close second, with a precise meaning: no payment is ever counted twice, and the number for any second that's more than a few minutes old matches the payments database exactly. The live edge can lag by a handful while late events arrive. The counter must never take payments down with it. It reads a copy of the payment events and sits off to the side. If the counter falls over, people lose a dashboard and nobody loses a payment. Ask for numbers. If the interviewer has none, propose two stages. Stage one is two payments a second and one person refreshing every ten seconds. Stage two is a peak of 5,000 payments a second and 10,000 open dashboards, which includes every wall screen and every curious engineer.

  • Peak payments: 5,000 a second. A number to propose for stage two. Ramp doesn't publish its own. It puts 300,000 payments inside any 60-second window.
  • Readers: 10,000 open dashboards. Each refreshing every 2 seconds is 5,000 reads a second, all asking for the same number.
  • Freshness target: about 2 seconds. From the payment being approved to the count on screen. Nobody watching a screen needs it faster.
  • Duplicate memory: about 150 MB. Remembering every payment id for 10 minutes is 5,000 times 600, or 3 million ids, at about 50 bytes each.

The object model, in words

A payment already exists in the payments database. It has an id, a status, an amount and an approval time. Nothing we build writes to it. It's the source of truth the counter is checked against. A payment event is a message saying a payment reached a new status. It carries the payment_id, the new status and occurred_at, the time the payment changed, which can be well before the event reaches us. The same event can be delivered twice, so the payment id is what we deduplicate on. A second bucket is the count of approved payments whose time falls in one particular second. The last 60 seconds is the sum of 60 buckets. A bucket is provisional while late events can still land in it and settled once the reconciler has checked it against the database. The current count is that sum with an as_of time, cached so every reader gets the same answer.

Where each record lives
TableFields
payments (existing database)payment_id · status · amount · occurred_at
payment events (event log)payment_id · status · occurred_at · published_at
second buckets (counts store)second · count · settled
current count (cache)count · as_of · stale
The payments table is the only one the business depends on. Everything below it can be rebuilt from it.

The API

Readers only read. Events come in from the event log, so there's no write endpoint at all. Three calls cover the dashboard, and the stream is for wall screens that stay open all day.

The interface
RequestFire-and-forget
DashboardCount APIthe live number
GET /payment-count?window=60s
count, as_of, stale
as_of lets the page say how old the number is instead of passing off a stale zero as real.
DashboardCount APIrecent history for a sparkline
GET /payment-count/history?minutes=15
points of (second, count), as_of
Count APIWall screenone update a second
GET /payment-count/stream
server-sent events carrying count and as_of

Stage one, for one reader

With one reader and two payments a second, don't build a pipeline. Add an index on the payment time, point the dashboard at a read replica of the payments database, and run one query on each refresh.

sql
SELECT count(*) FROM payments
WHERE status = 'approved'
AND occurred_at > now() - interval '60 seconds'

The index turns this into a scan of about 120 rows, so it's instant. It's exact, since it reads the source of truth. It's built in an afternoon. Duplicates can't happen either, because each payment is one row. Saying this first is the scrappy answer, and it gives you a baseline to measure the bigger design against. Then do the math that breaks it. At stage two the window holds 300,000 rows, and 5,000 reads a second would scan 1.5 billion index entries a second. That load lands on a replica of the database that payments depend on. The fix is to stop counting at read time and count once, as payments happen.

Stage two, at scale

The scaled design counts each payment once on the way in and serves one cached number to everyone. In the diagram, blue is outside what we're building, violet is a service we run, amber is the event log, and green is stored state.

Loading diagram...

1) A payment is approved. The Payments service writes the payment and an outbox row in one transaction in the Payments database. Within a few hundred milliseconds the Outbox relay picks the row up and publishes it to the Payment event log, keyed by payment id. Nothing on the payments path waits for any of this, so a slow dashboard can't slow a card swipe.

2) The event is counted once. The Stream counter reads the event, checks the payment id against the ids it has seen recently and skips it if it's a repeat. Otherwise it adds one to the bucket for the second the payment happened in. Every second it writes the changed bucket totals to Per-second counts. How it treats repeats and late arrivals is the first deep dive.

3) Everyone reads one number. Once a second the Count API sums the last 60 buckets, stamps the result with the time, and holds it in memory. Admin dashboards poll it or hold a stream open. Ten readers or ten thousand, the store sees the same few reads a second.

4) The number gets checked. The Reconciler compares each closed minute against the database and overwrites any second that's off. This is what lets us promise that old seconds are exact while the live edge stays fast.

Technology choices

  • The Payments database is whatever already holds payments, likely Postgres. The outbox table lives in the same database because that's the only way the payment and its event commit together. A separate write to the log after the commit would lose the event whenever the service crashed between the two.
  • The Payment event log is Kafka. A log fits better than a work queue here because events stay after they're read, so a new consumer or a rebuild can replay a day of payments. Partitions, the ordered slices a topic is split into, are keyed by payment id. If a broker dies, a replica takes over its partitions and consumers resume from their saved offsets, their position in each slice.
  • The Stream counter is Flink or Kafka Streams. Either one keeps state per partition and checkpoints it together with the log offsets it has consumed. After a crash it restores the checkpoint and replays from those offsets, so the state comes back as if the crash never happened.
  • Per-second counts live in Redis, a fast in-memory key-value store. Each key is small and short-lived. If Redis loses its data, the counter rewrites the last hour of buckets from its own state, and the reconciler catches anything older.
  • The Count API is a plain stateless HTTP service behind a load balancer, with the current count held in memory. Wall screens get server-sent events, a long-lived HTTP response the server pushes lines down, which browsers reconnect on their own.

Name the popular tool and defend the category. What the interviewer is checking is that you know why the events need a replayable log and why the counts need idempotent writes.

Potential deep dives

Exact or fresh? Duplicates and late events

Expect this one first. Counting is easy until the same payment arrives twice or a minute late. Events arrive more than once because every hop retries. The relay republishes after a crash, and the log redelivers after a consumer restart. Events also arrive late. The relay can fall behind during a database failover, and a partition can stall while a broker fails over. Exact and instant at the same time isn't possible. So pick which number is which.

Duplicates have a clean answer. Each payment has one id, so the counter keeps a set of ids it has seen in the last ten minutes and counts an id only the first time. Ten minutes is far longer than any retry loop. At peak that's about 3 million ids, or 150 MB, split across all the counters. Because events are partitioned by payment id, every copy of one payment reaches the same counter, so no instance has to ask another.

if payment_id seen in the last 10 minutes: skip
if occurred_at is older than 10 minutes: leave it to the reconciler
remember payment_id
bucket[second of occurred_at] += 1

Late events land in the bucket for the second the payment happened in. That's event time, and it matters. Bucketing by arrival time would turn a five-minute broker stall into a fake spike when the backlog drains, which is exactly the moment someone is staring at the screen. With event time, the late payments fill in the seconds they belong to. In exchange, the newest seconds can still change. So the live number is fresh but provisional, and the API says so with as_of. After ten minutes a bucket stops taking events and waits for the reconciler. Once checked, it's settled and exact. For the person at the wall screen, the number runs a few payments light for a moment while stragglers arrive. For anyone looking back an hour later, it's exact.

The Ramp angle
Late events are where this stops being a toy. Payment events pass through several systems, each with its own retries and its own clock. Explain how a delayed approval should move the number and what the screen shows meanwhile. That's the product thinking the round is graded on.

How do we keep a rolling 60-second count cheap?

The window has to slide every second. Done naively, every refresh recounts 300,000 payments, and at 5,000 reads a second that's 1.5 billion rows of work a second for a number that changes once a second.

BadCount the rows on every read

Approach

Keep the stage-one query and add read replicas as readers grow, maybe with an index on status and time.

Challenges

Every reader repeats the same work, and the cost grows with readers times payments. Replicas lag their primary by a few seconds under heavy write load, so the count goes stale exactly when traffic peaks. And all of this load sits on infrastructure the payments path depends on. It's the right answer for stage one and the wrong one for stage two.

GoodSixty one-second buckets in one process

Approach

One consumer reads the event log and keeps a ring of 60 counters, one per second, plus a running total. When a new second starts, it subtracts the oldest bucket from the total, zeroes it and reuses it. A read is one number. It's a few lines of code and handles 5,000 events a second on one core.

Challenges

It's one process. If it restarts, the window is empty for a minute and the dashboard reads zero, the worst number it could show. It can only grow as far as one machine. And a ring indexed by the current second buckets by arrival time unless you add care for late events, which then need a bucket that the ring may already have recycled.

The Good tier's real problem is that the window lives only in one process's memory. Moving it somewhere shared, and splitting the counting across machines, is what forces the next step.

GreatPartitioned counters, buckets by event time, one sum a second

Approach

Each counter instance owns some log partitions and keeps buckets keyed by the second the payment happened in. Every second it writes changed bucket totals to the counts store under a key per second and partition. The Count API sums 60 seconds across, say, 12 partitions, which is 720 small numbers, once a second. It caches the result for every reader. Late events update old buckets, and the next sum picks them up.

Challenges

Partitioning by payment id means no single key takes every write, which partitioning by second would do. The cost is a sum across partitions at read time. That's cheap at 720 numbers, but it grows if you add dimensions like merchant. The window is only as fresh as the slowest partition, so the number's as_of should be the time that partition has caught up to.

Longer windows come from the same buckets. An hour is 3,600 one-second buckets, or 60 minute buckets if you roll them up. The scaling writes lesson covers splitting a hot counter across partitions in general.

How does the count survive a crash without counting twice?

Quick designs usually break here. The counter reads an event, updates a count, and records its place in the log. Those are separate steps, and a crash can land between any two of them. With 5,000 payments a second, a crash that replays the last ten seconds is 50,000 events to get right.

BadIncrement a Redis counter, then commit the offset

Approach

For each event, run INCR on a key for its second, then commit the consumer offset to Kafka every few seconds.

Challenges

If the counter crashes after incrementing and before committing, the restart replays those events and increments again. Every crash inflates the count, and nothing records by how much. A Redis failover can also drop the last increments, so the count drifts low too. So it errs in both directions, invisibly, and the only fix is a rebuild from scratch.

GoodDeduplicate in the store

Approach

Before incrementing, the counter writes the payment id to Redis with "only if absent" and a ten-minute expiry, in the same small script as the increment. A replayed event finds its id already there and skips. Crashes and redeliveries stop inflating the count.

Challenges

Redis now holds 3 million id keys and takes two writes per payment. Its replication is asynchronous, so a failover can lose the last second of ids and counts together. The count drifts low, and the replay that should fix it can't tell what was lost. It's much better, but the store is now both the dedup memory and the answer, and neither is durable.

GreatCheckpointed counter state, idempotent bucket writes

Approach

Keep the seen ids and the open buckets inside the stream processor, and let it checkpoint them together with the log offsets every few seconds. After a crash, it restores the last checkpoint and replays from those offsets. The state comes back as of the checkpoint, so each event is counted exactly once in state. For each second and partition, the counter writes the total, say 412, as a plain overwrite. It never sends an increment.

Challenges

Overwrites are what make the output safe. A replay may write the same total again, and writing the same value twice changes nothing. Redis becomes a disposable view the counter can repaint in a second. The cost is running Flink or Kafka Streams, with checkpoint storage and people who know how they fail. For stage one, that's far too much.

One gap is left, upstream. If the payments service published to Kafka directly after committing, a crash between the two would lose the event forever and no replay could find it. An outbox closes that gap. Its row commits with the payment, and the relay keeps retrying until the event is published. The Kafka toolbox page covers offsets and consumer groups in more depth.

What changes when thousands of people watch the number?

This is the other half of the prompt's growth, and it's easier than it sounds. The count changes at most once a second. Ten thousand readers polling every two seconds is 5,000 requests a second for a value there's only one of. Compute it once and hand out copies.

Compute once a second

One Count API instance, picked by a short lease in Redis, sums the buckets each second and writes the current count back as a single key. If that instance dies, another takes the lease within a few seconds. The store sees one sum a second whatever the traffic.

Serve from memory

Every API instance reads that key once a second and answers requests from memory. Ten instances handle 5,000 requests a second at 500 each, which is nothing for a service returning a few bytes. Requests that arrive together share one refresh instead of each going to Redis.

Push to wall screens

A screen open all day can hold a server-sent events stream and get one message a second, which beats it polling. Browser tabs that come and go can poll. With 10,000 viewers, push is 10,000 tiny messages a second spread across instances.

Never fake a zero

Every response carries as_of. If the number is more than ten seconds old, the page greys it out and says the data is delayed. A stale count shown as live is the failure that sends someone hunting for an outage that isn't there.

If readers grew another hundred times, put a CDN or a shared HTTP cache in front with a one-second lifetime. Polling every two seconds still feels live to a person, and the scaling reads lesson covers caching layers in general. The real-time updates lesson compares polling, server-sent events and WebSockets.

How do we know the number is wrong, and fix it?

Even a careful pipeline drifts. A relay bug drops a batch, a deploy double-publishes, a clock is off by a minute, an event shows up an hour late. A counter with nothing checking it will be wrong eventually and nobody will know. The reconciler is what turns "probably right" into "checked".

1

Wait for a minute to close

Every minute, take the minute that ended ten minutes ago. By then almost every late event has arrived and the counter has stopped taking events for it.

2

Count it from the source

Ask a database replica for the approved payments in that minute, grouped by second. With an index on time that's 60 rows back from about 300,000 scanned, once a minute.

3

Compare and overwrite

For each second, compare the database's number with the stored bucket. A match gets marked settled. A mismatch gets overwritten with the database's number, since the database is the truth.

4

Record the drift

Log every mismatch and its size as a metric. A drift of zero most minutes, with the odd one-off, is healthy. A steady drift in one direction means a bug, and its sign says whether something is losing events or duplicating them.

For big damage, like an hour of bad buckets after a bad deploy, don't patch second by second. Stop the counter, reset its state, and replay the event log from before the problem. Kafka keeps seven days, and the counter rebuilds an hour of buckets in a minute or two, since it's only adding ones. The reconciler then checks the rebuilt seconds like any others.

Monitoring follows the same logic. Alert on freshness first, meaning how old the newest bucket is compared with the clock, because that's what the reader sees. Watch consumer lag on the log, which tells you why freshness slipped. Track the duplicate rate, since a spike means a producer is stuck retrying, and track drift per reconciled minute. Then add one product alert: approved payments falling far below the same minute last week. That's often the first sign of a real payments outage, which makes the dashboard useful well beyond a wall screen. The monitoring and observability page covers metrics and alerting in general.

The Ramp angle
At a company that moves money, a count that disagrees with the ledger costs trust fast. Say early that the stream counter makes the number fresh and the reconciler makes it exact. Show the drift you'd alert on. That answers "exact versus fresh" with a mechanism the interviewer can poke at.

Practice the core in code

One class holds the core of this design. It drops duplicate payments by id, puts each payment in the bucket for its approval second, sums a sliding window on demand, and lets a reconciler overwrite a second with the true count. There's no log, store or clock here. Timestamps are whole seconds passed in by the caller.

1

Live payment counter with dedup and reconciliation

Medium
Problem
A dashboard shows how many payments happened in the last window_seconds seconds. Payment events can arrive twice and out of order, and a reconciler sometimes corrects the count for one second.

Write a class PaymentCounter whose constructor takes window_seconds. record(payment_id, timestamp) returns true and counts the payment in the second timestamp the first time that id is seen. It returns false and changes nothing for any later event with the same id, even one with a different timestamp.

count(now) returns the number of counted payments with a timestamp t where now - window_seconds < t <= now. Payments later than now aren't included. reconcile(timestamp, true_count) sets the count for that one second to true_count and returns true_count minus the count it had before, which is the drift.

Input encoding. A test case is a JSON array of operations. The first entry is ["PaymentCounter", [window_seconds]] and each later entry is [method, [args]]. The expected array holds each operation's return, with null for the constructor.
  1. PaymentCounter(60)
  2. record("p1", 100)→ true
  3. record("p2", 130)→ true
  4. record("p1", 100)→ false
  5. count(130)→ 2
  6. count(160)→ 1
  7. count(190)→ 0

The second p1 is a redelivery, so it isn't counted. At 160 the window covers seconds 101 to 160, which leaves only p2. At 190 both have aged out.

How this uses the pattern

Keep a set of seen payment ids and a dictionary from second to count. Counting is a sum over the seconds in the window, and reconciling is an overwrite of one entry.

Write it here, or go full screen with the problem, hints and solution beside the editor.

Live payment counter with dedup and reconciliation

Loading...
Click "Run" to execute your code
The Ramp angle
This is the stream counter and the reconciler from the design, small enough to run. The tests that catch people are the redelivered event with a different timestamp, which must still be skipped, and the late event, which belongs to the second it happened in. State the window's edges before you code, since an off-by-one there is the most common failure.
Take it further
Ask how long the seen set can grow, then bound it by forgetting ids older than ten minutes, the way the counter does. Next, make count constant time with a running total that drops the oldest second as the window moves, and say what a late event does to that total. Finally, add a merchant field and count per merchant.

Follow-ups to be ready for

Break it down by merchant or by card program. The buckets gain a dimension, so the key becomes second plus merchant. With a few hundred merchants that's fine. With a million, only keep exact counts for the top few hundred, and send the full breakdown to an analytics store such as ClickHouse that people query on demand.

Count dollars as well as payments. Add an amount to each bucket alongside the count. Refunds and reversals arrive as their own events, so decide whether they subtract from the minute the payment happened in or the minute they happened in. For a live screen, the minute they happened in is easier to explain.

Distinct cards in the last minute. Distinct counts don't add up across seconds, since one card can appear in many. Keep a small HyperLogLog sketch per second, which estimates distinct counts within about 1 percent and merges across seconds. Redis has one built in.

A second region. Run a counter in each region over that region's payments, and sum the regions in the Count API the same way it sums partitions. Each region's lag becomes part of the as_of time.

What is expected at each level

Ramp's ladder runs IC3 for new grads through IC6 for staff. Intern and new-grad loops report none. From IC4 up, a design question like this one can come as its own slot or as the short exercise at the end of a project deep dive, so the bar below assumes 20 to 45 minutes.

IC4 (Software Engineer)

Roughly 80/20 breadth to depth. You define what counts as a payment, give the stage-one query, and explain with numbers why it fails at scale. You reach an event log feeding per-second buckets and a cached count, and you know a redelivered event must not count twice. The bar: a working design for both stages and a clear dedup rule.

IC5 (Senior)

Roughly 60/40. You raise event time against arrival time yourself, and you separate the fresh live number from the exact settled one. Checkpointed state and overwrite writes close the crash window, and the outbox shows up without being asked. So does as_of on the screen. The bar: you find the duplicate, late-event and crash problems before the interviewer points at them.

IC6 (Staff)

Roughly 40/60. You treat the reconciler and its drift metric as the source of trust, plan the rebuild from the log, and size the cost of each stage. You know when to stop: stage one may be all a small team needs for a year. Ask the recruiter what the staff slot looks like. The bar: you pick which deep dives matter and size each tradeoff, and the interviewer mostly steers.

Common questions

Is this the same as the "design a hit counter" problem?

Both count events in a sliding window. The interview version adds what a coding problem skips. Events arrive twice and late, the counter can crash, many people read one number, and the number has to match the database.

How long is this question in the Ramp system design interview?

It varies. In January 2026 it took the final 20 minutes of a project deep dive. The July and August 2026 payments versions came as onsite design questions that start small and grow. Prepare a 20-minute version and a 45-minute version of the same design.

Key Takeaways

  • ✓Ask who reads the number first, then start with one indexed database count for one reader.
  • ✓At scale, count each payment once on the way in: an event log, per-second buckets by event time, one cached sum a second.
  • ✓Deduplicate by payment id, checkpoint counter state with log offsets, and write bucket totals as overwrites.
  • ✓Keep the live edge fresh and let a reconciler settle old seconds against the database, alerting on drift.
Ramp interview guide

Know what Ramp asks before you walk in.

29 coding · 3 system design · 18 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

The Ramp System Design RoundHad your Ramp interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.