Designing a Continuously Refreshed Merchant Attribute Store
System DesignModel answerLast updated
Design a platform that links merchants to external sources, refreshes their attributes on schedule, resolves conflicts with provenance, and serves low-latency reads even when upstreams fail.
Problem
A marketplace shows a profile for each of its merchants. The profile includes a headquarters address, social follower counts, and a few encyclopedic facts such as founding year and parent company. None of this data is owned by the marketplace. It has to be gathered from outside providers: social network APIs, official business registries, a maps/geocoding service, and a public knowledge graph like Wikidata.
Design the backend that keeps this data accurate and current, and makes it quickly available to other internal services.
Capabilities required
- Linking. Connect each internal merchant ID to the matching identifiers at each provider (a social handle, a knowledge-graph entity ID, a registry record), starting from signals like the merchant's domain or brand name.
- Collection. Pull fast-changing metrics (follower counts) on a regular schedule. Pull slow-changing facts (address, founding year, parent company) less often. Also handle on-demand re-sync requests from merchants.
- Traceability. Every attribute value shown must carry where it came from, how confident the system is in it, and when it was observed.
- Graceful degradation. If one provider is throttled or offline, profiles must still be served using the most recent good values from that provider.
- Serving. Internal consumers (profile pages, ranking) need fast reads of the current state, plus access to historical snapshots.
Scale and targets
- 50 million merchants in total.
- About 5 million "active" merchants need follower counts refreshed daily. The other 45 million refresh weekly.
- Follower metrics should be no more than 24 hours old. Address and fact changes should be reflected within 7 days.
- Reads: 20,000 per second with P99 latency under 25 ms.
- The full change history must be retained for compliance and debugging.
What to cover in your answer
- The data model: dynamic attributes, provenance, confidence, and time-series history.
- The architecture: scheduling, rate-limited fetching, parsing, entity matching, and reconciliation.
- How you resolve disagreements between sources, for example two registries listing different addresses.
- Failure handling: provider throttling, breaking changes in provider payloads, and malformed records that repeatedly crash workers.
State your assumptions and do rough capacity math as you go.
Hints
Hint 1
Compute the average request rates first. Roughly 11M social refreshes per day is only on the order of 100 per second, so the real bottleneck is provider quotas and data quality, not raw throughput.
Hint 2
Separate the write side from the read side. Keep an append-only observation log as the source of truth, and derive a precomputed per-merchant record that reads hit with a single key lookup.
Hint 3
Do not use one global merge rule. Choose a policy per attribute type (latest-wins for metrics, authority-weighted scoring for addresses, multi-source agreement for facts), and mark unresolved authoritative conflicts as disputed rather than silently choosing.
Hint 4
For failures, think in layers: per-provider token buckets and circuit breakers, versioned parsers with a quarantine queue for payloads that fail validation, and a dead-letter path with a retry cap for poison messages.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size
Confirm the consumers: the profile page wants the current resolved value, ranking wants bulk feature reads, and compliance wants history. Also confirm that consumers want a single resolved value per attribute with provenance attached, not raw per-source values.
Rough numbers
| Item | Estimate |
|---|---|
| Social refreshes | 5M daily + 45M/7 weekly, about 11.4M/day, about 130 req/s average (plan for 3-5x peaks) |
| Fact refreshes | 50M per 7 days, about 7M/day, about 80 req/s across registries, maps, and the knowledge graph |
| Reads | 20K QPS at P99 < 25 ms, so a precomputed key-value lookup with no joins or fan-out |
| Current records | 50M x ~4 KB, about 200 GB, fits a partitioned KV store plus a cache |
| Metric history | 11.4M x ~100 B, about 1.1 GB/day, about 400 GB/year in a columnar or time-series store |
| Raw payloads | Compressed in object storage, tens of TB/year with lifecycle tiering |
The takeaway is that write throughput is modest. Provider quotas, correctness, and resilience are the hard parts.
2. API sketch
GET /merchants/{id}/profile?fields=...&include=provenanceGET /merchants/{id}/history?attribute=...&from=...&to=...POST /merchants:batchGetfor ranking (bounded batch size)POST /merchants/{id}/resync(rate-limited per merchant)POST /merchants/{id}/claimsfor merchant-submitted values
3. Data model
- Entity links:
(merchant_id, source, external_id, match_score, method, status[candidate|verified|rejected], verified_at). Only verified links feed enrichment. - Observations (append-only):
(merchant_id, attribute, source, external_id, value, normalized_value, confidence, observed_at, ingested_at, raw_payload_ref, parser_version). This is the source of truth and the audit trail. - Current record (served): one document per merchant, where each attribute has
value, source, confidence, observed_at, resolved_at, status, alternates[], plus a record version. - Changelog (append-only):
(merchant_id, attribute, old, new, reason, policy_version, ts). This supports audits and replay of reconciliation after a policy fix.
Storage: a wide-column or key-value store (Cassandra/DynamoDB style) sharded by merchant ID for the current record; columnar or time-series storage for observations and metric history; object storage for raw payloads.
4. Architecture
Pipeline: Scheduler -> per-provider priority queues -> token-bucket rate limiter -> fetch workers -> raw landing (object store + log) -> parser/normalizer -> entity resolution -> observation store -> reconciler -> current-record store + cache -> read API.
- Scheduler. Maintain a "next due" index keyed by provider, due time, and priority. Daily tier for active merchants, weekly for the rest. Resync requests and provider webhooks enter at high priority. Deduplicate so each merchant has at most one in-flight job per provider. Add jitter to avoid synchronized bursts.
- Fetch workers. Stateless, horizontally scalable, pulling from provider-specific queues so that one slow provider cannot block the others.
- Entity resolution. Three stages: (1) deterministic matches (verified domain, social link on the merchant's site, registry number); (2) probabilistic matching with name similarity, geography, and category via a scored model; (3) gray-zone candidates go to human or merchant confirmation. Links are versioned so a bad merge can be rolled back.
- Read path. Reads touch only the materialized current record. Use an in-process or Redis cache in front of the KV store, invalidated by change-data-capture from record writes. A cache hit plus one KV lookup comfortably meets P99 < 25 ms at 20K QPS. Batch reads hit the same store with multi-get.
Decoupling ingestion from serving is what delivers graceful degradation: if a provider is down, ingestion for it pauses while reads continue returning the last known good value with its observed_at and a stale flag once it exceeds the SLA.
5. Conflict resolution
- Normalize first. Parse and geocode addresses so formatting differences ("St." vs "Street", suite numbers) are not treated as conflicts.
- Per-attribute policy.
- Metrics: one canonical source per platform, latest value wins; never average across sources.
- Legal/HQ address: score = source trust for that attribute x confidence x recency decay. Typical authority order: government registry, then merchant-verified claim, then maps, then knowledge graph, then unverified claims.
- Facts (founding year, parent company): agreement voting across independent sources, with a boost when they agree.
- Authoritative disagreement. When two top-tier sources conflict, do not silently pick one. Serve the higher-scoring value with
status: disputed, keep the other underalternates, open a review task, and make trust badges requireverified. - Hysteresis. Require a new value to persist across several observations or exceed a score margin before replacing the current one, to prevent flapping.
6. Failure modes
- Throttling (HTTP 429). Use a centralized token bucket per provider and credential, sized below the published quota. Reduce the rate multiplicatively on 429s and recover additively (AIMD). Honor
Retry-After. A per-provider circuit breaker keeps jobs queued while open; reads serve stale-flagged data. - Breaking schema changes. Parsers are versioned with contract tests. Validate payloads against a schema; on failure, quarantine the raw payload instead of writing observations, alert when the failure rate crosses a threshold, and keep serving the old value. After shipping a parser fix, replay quarantined payloads from raw storage.
- Poison pills. Cap retries with exponential backoff, then route to a dead-letter queue with the payload reference and error. Isolate per-message failures so one bad record never blocks a partition. Add sanity checks (for example, a follower count dropping 99% overnight is held for confirmation).
- Duplicates and out-of-order delivery. Make writes idempotent by keying on
(merchant, attribute, source, observed_at)and ignore observations older than the current one. - Cold or never-refreshed merchants. Track per-attribute freshness and alert on SLA breaches rather than only on job failures.
7. Trade-offs and common mistakes
- Resolving at write time (precomputed record) costs storage and reconciliation work but is the only way to hit the latency target; resolving at read time would require fan-out.
- Averaging or "last write wins" across sources is a frequent mistake and loses provenance.
- Treating the read API and ingestion as one failure domain makes a provider outage a profile outage.
- Forgetting entity-resolution errors: a wrong link silently poisons every attribute from that source, so links need confidence, review, and rollback.
- Ignoring quotas: the average load is small, but without central rate limiting, retries and bursts can exhaust a provider quota and stall refreshes for everyone.