Scrivio Interview library
DesignAdvanced7 min read · updated 13 November 2026

4,000 partners keep local copies of their catalogue in sync with your platform by paging through GET /products?updatedSince=... every 5 minutes. Partners report missing deletions and occasional missed updates, and the sync queries are 30 percent of database load.

Design a change feed API that replaces this sync, including how cursors, deletes and expired cursors work.

Instead of letting partners poll updatedSince, we publish every change as an ordered, per-tenant log fed by an outbox or CDC, give each change a monotonically increasing sequence assigned at commit, and expose GET /changes?cursor=... that returns changes after that sequence. Deletes become explicit tombstone records, each change carries the full resource so partners can apply it idempotently, the feed is kept for a fixed window such as 30 days with 410 Gone and a snapshot resync for older cursors, and it is served from the log store with webhooks that only say 'new changes exist'.

Why this question is asked

Keeping a copy of data in sync with another system is one of the most common integration problems, and the 'give me everything updated since T' query is the most common first attempt. It looks simple, but it quietly loses data and it is expensive at scale. Interviewers ask this to see whether we understand why timestamps are not cursors, how deletions are represented, and how a feed API behaves over months of operation. In this answer, we will see exactly why the current sync misses updates and deletions, then design the change log, the feed endpoint and its cursors, explain tombstones and idempotent apply, handle expired cursors, and finally take the load off the primary database.

1Why updatedSince Misses Changes

Two things go wrong with GET /products?updatedSince=T. The first is deletions. A deleted product is no longer in the table, so no query on the table can return it. Partners never learn that it is gone, and their copies keep products we stopped selling.

The second is subtler. updated_at is usually set when the row is written, not when the transaction commits. Imagine transaction A updates product 1 at 10:00:00.100 but commits at 10:00:00.900, while a partner's poll runs at 10:00:00.500 and records 10:00:00.500 as its next updatedSince. A's change was invisible during that poll, and the next poll asks for changes after 10:00:00.500, so the row stamped 10:00:00.100 is never returned. Clock differences between application servers make this worse. So the sync loses updates by design, and adding a safety overlap only reduces the loss while adding duplicates.

Finally, 4,000 partners each running a range query every 5 minutes against the main products table is a lot of repetitive load, which is why sync queries reach 30 percent of database load.

2The Change Log and Its Sequence Numbers

The core of the design is an ordered log of changes per tenant. Whenever a product is created, updated or deleted, the same database transaction also inserts a row into an outbox table, a table whose only job is to record events that must be published. A relay then publishes outbox rows to the log store, which could be a Kafka topic partitioned by tenant or a dedicated changes table. Change data capture (CDC), reading the database's write-ahead log with a tool such as Debezium, is an alternative that needs no outbox writes in the application code.

Each change gets a sequence number that only grows within the tenant and is assigned in commit order. With CDC, the log position of the commit gives that order naturally. With an outbox, the relay can assign sequences as it reads committed rows, or the log store's own offsets (a Kafka partition offset) serve as the sequence. The important property is that a change becomes visible to readers only with a sequence higher than everything readers have already seen, which is exactly what the updated_at approach lacked.

Step throughChange feed architecture
  1. Catalogue servicewrites product row and outbox row in one transaction
  2. Outbox relay or CDCreads committed changes in commit order
  3. Change log per tenantKafka topic or changes table, sequence per tenant, 30-day retention
  4. Changes APIGET /changes?cursor=..., reads the log, never the product tables
  5. Signal webhookPOST 'changes available' to the partner
  6. Partner sync jobapplies changes in order, stores the last cursor

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

The feed reads from the log store, so partner syncs no longer touch the primary tables.

3The Feed Endpoint, Cursors and Tombstones

Partners call GET /changes?cursor=c, and the API returns up to, say, 500 changes with a sequence above the cursor, plus next_cursor. The cursor is opaque to the partner but in practice encodes the tenant and the last sequence. A partner that has caught up receives an empty list and the same cursor, and asks again later.

A deletion is not the absence of a row in the feed; it is a record of its own, a tombstone that says 'product 42 was deleted at sequence 1007'. Each upsert change carries the full current state of the resource, not a diff, so partners can apply it without fetching anything and can apply it twice without harm. A partner applies changes in sequence order: an upsert replaces its copy, a tombstone deletes it. Because each record is a full state and records are ordered, applying the same page again after a crash leaves the same result, which makes the partner's job idempotent. The partner stores next_cursor only after it has applied the page.

Java
GET /changes?cursor=eyJ0IjoicDk4MSIsInMiOjEwMDV9&limit=500
{
"changes": [
{ "seq": 1006, "type": "upsert", "id": "prod-17", "resource": { "id": "prod-17", "price": 1999 } },
{ "seq": 1007, "type": "delete", "id": "prod-42" }
],
"next_cursor": "eyJ0IjoicDk4MSIsInMiOjEwMDd9", // seq 1007
"has_more": false
}

Notice that the deletion of prod-42 is a change like any other, with its own sequence number. With the old API that deletion was invisible.

4What Happens When a Cursor Is Too Old?

We cannot keep every change forever, so the feed has a fixed retention, for example 30 days. If a partner comes back with a cursor older than the oldest retained change, we cannot tell them what they missed. The API returns 410 Gone with an error code such as cursor_expired and a link to the resync procedure.

The resync works by combining a snapshot with a cursor. The partner starts a snapshot export of the full catalogue; the export is taken at a known log position and returns that position as a cursor along with the files. The partner replaces its copy with the snapshot and then reads the feed from the snapshot cursor. Changes that happened during the export are replayed from the feed, and since every change is a full state applied in order, any overlap is harmless. The same mechanism serves new partners on their first day.

Step throughPartner sync loop
  1. Call GET /changes with the stored cursor
  2. Response is 410 Gone?
    YesRun snapshot export, load it, store its cursorNoApply changes in order
  3. Store next_cursor after applyingonly after the page is fully applied
  4. has_more is true?
    YesCall again at onceNoWait for a webhook signal or 5 minutes

4 steps in order. Play them, or step through them one at a time.

5Taking Load Off the Database and Ending Blind Polling

The feed is served from the log store or a read replica of the changes table, never from the product tables, so partner syncs stop competing with the core workload. Reading 'changes after sequence N for tenant T' is an index range scan on (tenant, seq) or a sequential read of a Kafka partition, both cheap. Old changes are dropped by deleting partitions or by Kafka retention, not row by row.

To stop 4,000 partners from polling every 5 minutes when nothing changed, we add a webhook that only signals: 'tenant p-981 has new changes'. It carries no data, so a lost or duplicated signal is harmless; the partner simply reads the feed. We keep a slow fallback poll, for example every hour, in case signals are missed. Most partners then call the feed only when there is something to read.

6Follow-up questions

How would you let a partner replay changes from a week ago after a bug on their side?

Because the feed keeps 30 days of changes and the cursor is just a position, the partner can restart from an older cursor. The simplest support is to let them request a cursor for a point in time, for example GET /changes/cursor?at=2026-11-06T00:00:00Z, which returns the first sequence after that time. They read from there and reapply everything; since each change is a full state applied in order, reapplying changes they had already processed gives the same result. If the bug is older than the retention window, they fall back to the snapshot resync.

Why not let partners subscribe to Kafka directly?

Some large partners may want that, but exposing our internal topics couples them to our internal schema, partitioning and security model. The HTTP feed is a stable public contract that we can serve from Kafka today and from another store later, with authentication and quotas we already know how to operate.

7Conclusion

In this answer, we saw why polling updatedSince loses deletions and late-committing updates and loads the primary database. We replaced it with an ordered per-tenant change log fed by an outbox or CDC, a cursor-based GET /changes endpoint, tombstones for deletes, full-state changes that partners apply idempotently in order, a 30-day retention with 410 Gone and a snapshot resync, and signal-only webhooks so partners stop polling blindly.

What to say in the interviewAbout 90 seconds aloud

Open with

The current sync has two built-in holes. A deleted product simply disappears from the table, so an updatedSince query can never return it. And updated_at is set when the row is written, not when the transaction commits, so a slow transaction can commit with a timestamp older than the partner's last poll and be skipped forever.

Then, if they want more

On top of that, four thousand partners polling the main table is thirty percent of our database load. I would replace it with a change feed.

Every create, update or delete writes an outbox row in the same transaction, or we use CDC from the write-ahead log, and a relay publishes those changes into a per-tenant log with a sequence number in commit order. Partners call GET /changes with an opaque cursor and get the changes after that sequence, plus a next cursor.

Deletes are explicit tombstone records, and each change carries the full current resource, so partners apply changes in order and can safely apply a page twice. We keep the feed for thirty days; an older cursor gets 410 Gone, and the partner resyncs from a snapshot export that comes with the cursor where it was taken.

The feed is served from the log store, not the primary tables, and a signal-only webhook tells partners when there is something new, so they stop polling blindly.

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 "Design a change feed API that replaces this sync, including how cursors, deletes and...": https://scrivio-interview-library.netlify.app/architecture/api-design-at-scale/d097f0d5c0/