Design a Versioned Product Catalog with Atomic Launches
System DesignModel answerLast updated
Design a multi-tenant catalog backend with draft/publish workflows, grouped launches, search, and safe rollback, serving 100K peak read QPS at P99 under 25 ms.
Problem
You are building the backend for a multi-tenant catalog used by merchants on a commerce platform. Merchants maintain product records, prepare changes as drafts, and release groups of products together for events such as seasonal launches or flash sales. Public storefronts and automated messaging systems read the published products heavily.
Design this service.
Functional requirements
- Lifecycle and history: Merchants create and edit drafts, publish a chosen draft, and instantly revert to any earlier published version.
- Grouped launches: Several products can be published together, atomically or in a tightly coordinated way.
- Lookup and search: Find currently published products by SKU, category, tag, or full-text query. Drafts must never appear.
- Flexible attributes: Products carry tenant-specific attributes (size, color, custom metadata). Schema changes must remain backward compatible.
Non-functional requirements
- Scale: 100,000 merchants, 100 million SKUs, 50,000 read QPS on average (100,000 at peak), 500 write QPS.
- Latency: Read P99 under 25 ms. A publish must reach the read layer in under 2 seconds.
- Availability: 99.99% for public reads, 99.9% for merchant writes.
- Consistency: Strong consistency when validating and publishing writes. Search and read projections may be eventually consistent within the latency target.
What to cover
- How drafts, published state, and history are stored without copying whole catalogs.
- The split between the authoring (write) side and the serving/search (read) side.
- How publishing stays safe under retries, partial failures, and out-of-order events.
- How caches and search indexes are updated, invalidated, and rebuilt with no downtime or stale reads.
- How a single product or an entire launch is rolled back without corrupting data.
Hints
Hint 1
Size things first: 100M SKUs at a few KB each is hundreds of GB for the live set and a few TB with history. Read traffic of 100K QPS under a 25 ms P99 implies a heavy cache hit rate, so the origin sees only a small fraction.
Hint 2
Make versions immutable per-item snapshots and make publishing a pointer change (published_version_id). Then rollback is just another pointer change, and a launch is a set of pointer changes in one transaction when data is sharded by tenant.
Hint 3
Avoid dual writes: commit the publish and an outbox event in the same transaction, stream it to projectors, and give every event a monotonically increasing per-tenant sequence number so projectors can use conditional writes and ignore stale or duplicate messages.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Sizing and framing
- Storage: 100M SKUs at roughly 4 KB per version is about 400 GB of live published data. Keeping around 10 versions per item gives about 4 TB of history. This does not fit one node, so the authoring store is sharded by
tenant_id. - Reads: 100K peak QPS with a CDN plus Redis at about 95% hit rate leaves roughly 5K QPS for the read store. That is what makes P99 under 25 ms realistic.
- Writes: 500 QPS is small. The hard part is correctness and bursts (bulk imports, flash-sale publishes), not raw volume.
- Skew: Tenant sizes follow a power law. A few giant merchants (millions of SKUs) need dedicated shards or sub-partitioning.
Inventory and pricing are adjacent systems and out of scope; say so explicitly.
2. Data model (authoring store, Postgres sharded by tenant)
items(tenant_id, item_id, sku, draft_version_id, published_version_id, publish_seq, row_version), with SKU unique per tenant.item_versions(tenant_id, item_id, version_id, schema_version, core fields, attributes JSONB, content_hash, created_at). These rows are immutable.releases(release_id, status, publish_at, idempotency_key)andrelease_items(release_id, item_id, target_version_id, prior_version_id).outbox(tenant_id, seq, event_type, payload)andidempotency_keys(tenant_id, key, request_hash, response, expires_at).
Key decisions:
- Versions are per-item snapshots, not catalog trees. A release references versions instead of copying them.
- Publishing and rollback only move
published_version_id, an O(1) update. content_hashavoids storing identical versions twice; images and blobs live in object storage as URLs.- Dynamic attributes go in JSONB, validated against a per-tenant schema registry, with
schema_versionstamped on every version. Only additive or optional changes are allowed, so old versions stay readable. - Old unreferenced versions are compacted to cold storage under a retention policy.
3. Architecture (CQRS)
Write path: Merchant UI, authoring API, Postgres. The outbox row is written in the same transaction, then CDC (for example Debezium) pushes it to Kafka keyed by tenant:item. Projectors consume and update:
- a read store (DynamoDB or Cassandra) holding the published document per item,
- a search index (Elasticsearch/OpenSearch) for category, tag, and full-text queries over published items only,
- caches (Redis and CDN purge by surrogate key).
Read path: CDN, read API, Redis, read store or search. Drafts never leave the write side.
4. Publishing pipeline
Single item. One transaction validates the version against the schema, checks row_version (optimistic concurrency via If-Match), sets published_version_id, increments the per-tenant publish_seq, and inserts the outbox event. The outbox removes the dual-write problem.
Coordinated release. Since data is sharded by tenant, a release is a single-shard transaction: all pointers flip or none do. For near-simultaneous storefront visibility, projectors pre-index release items with visible_from = publish_at, reads filter on visible_from <= now, and caches are warmed in advance. At go-live only the release status changes. This matters most in flash sales, where cold caches hurt the most.
Retry storms. Clients send an Idempotency-Key; the server stores the key, a request hash, and the response. Same key and same body returns the stored response; same key with a different body returns 422. Add per-tenant token-bucket rate limits and jittered client backoff.
Partial failures. The database commit is atomic. Projectors are at-least-once and idempotent: every projected doc stores publish_seq, and writes are conditional (seq > stored_seq in DynamoDB, external versioning in Elasticsearch). Poison messages go to a DLQ with alerts.
Out-of-order events. Kafka keyed by item preserves per-item order, and the sequence guard discards anything stale after rebalances or replays.
5. Projections and cache management
- Redis is read-through with key
item:{tenant}:{id}, value carriespublish_seq. CDN responses carry surrogate keys for tenant, item, and release. - Projectors purge caches after the read store write succeeds, so stale data is not re-cached.
- A short TTL (30 to 60 s) bounds staleness if a purge is lost. Request coalescing and stale-while-revalidate protect the origin during stampedes.
- Zero-downtime rebuild: create
catalog_v{n+1}, bulk-load from a consistent snapshot while recording the LSN or Kafka offset, replay from that offset until lag is near zero, then atomically swap the alias. Keep the old index for fast fallback. Sequence guards make the snapshot/replay overlap harmless. - Monitor end-to-end publish-to-visible latency (commit time stamped into events), consumer lag, and the gap between database seq and projection seq.
6. Rollback and recovery
- Item rollback is a new publish pointing at an older
version_id, with a new, higherpublish_seq. History is never rewritten, projectors treat it as a normal publish, and the seq guard cannot reject it as stale. - Release rollback is one transaction restoring each item's
prior_version_idfromrelease_items. Handle conflicts: if an item was republished after the release, either skip it and report it, or require an explicit force flag. - Recovery: the database is the source of truth. Any projection can be rebuilt from a snapshot plus the event log. Cross-region replicas and multi-AZ read stores support the 99.99% read target; the write path can degrade independently at 99.9%.
7. Trade-offs and common mistakes
- Sharding by tenant makes releases cheap and atomic but requires special handling for huge tenants. Cross-tenant launches would need sagas and are out of scope.
- Strong consistency on writes costs some write availability; that is acceptable at 500 QPS and a 99.9% target.
- Common mistakes: dual-writing to the DB and the index, purging caches before the store is updated, copying full catalogs per version, using wall-clock timestamps instead of sequence numbers for ordering, treating rollback as deleting history, and ignoring tenant skew.