Build a Fleet-Wide Error Frequency Tracking Platform
System DesignModel answerLast updated
Design a shared platform that ingests error logs from many apps, collapses similar messages into one signature, and answers count, trend and top-N queries reliably during incident spikes.
Your company runs hundreds of services, and each one emits error messages. You are asked to design a central platform that tells engineers how often each kind of error is happening.
Two raw messages that describe the same underlying problem rarely look identical. They may contain different request IDs, user IDs, timestamps, hostnames or numeric values. The platform must still treat them as one error.
Design the platform end to end. Your answer should cover:
- How a raw message becomes a stable grouping key (a signature), and which extra dimensions (service, region, release version) are counted alongside it.
- How the write path handles steady load and sudden incident bursts, where error volume can jump by 10x to 100x.
- How counts are stored and queried: count of one error over a time range, a per-error time series, and the top N errors in a recent window.
- How you deal with retries, late or out-of-order events, and component failures, and what accuracy guarantee you offer.
- Rough capacity estimates, retention and rollup policy, and how you would monitor the platform itself.
State your assumptions about scale and freshness up front, and mention which clarifying questions you would ask first.
Hints
Hint 1
Start by defining the counting key: a normalized message template plus service and a time bucket. Think about what to strip out (IDs, numbers, timestamps, paths) and whether to prefer a client-supplied error code or stack-frame hash when one exists.
Hint 2
Never write once per error to the database. Put a durable partitioned log in front, then pre-aggregate in memory over short windows (for example 10 seconds) so a burst of a million identical errors becomes a handful of increments.
Hint 3
Store counts in fixed time buckets (minute, hour, day) with rollups and different retention for each. Top-N over a recent window is a separate query shape: consider a per-window heap or a sketch rather than scanning every signature.
Hint 4
For correctness, decide your delivery semantics. At-least-once delivery plus idempotent bucket writes (keyed by partition and offset range) gives effectively exact counts; also decide how long late events are accepted.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and assume
Questions I would ask first: which queries matter (range count, time series, top N), which dimensions are needed, how fresh and how exact counts must be, retention, and whether alerting is in scope.
Assumptions for the rest of this answer:
- 500 services, steady state about 50k errors/s, incident peaks about 1M errors/s.
- Dashboards tolerate 30-60 s freshness. Counts should be exact after a short settle period, with approximate values acceptable for live top-N.
- Retention: 1-minute buckets for 7 days, 1-hour for 90 days, 1-day for 2 years.
- Alerting is a consumer of the same data, not part of the core.
Estimate: 50k/s is about 4.3B events/day. At roughly 300 bytes per event, that is about 1.3 TB/day raw, which is why we aggregate early and keep raw samples only briefly.
2. Counting key: error signatures
The key is (signature, service, region, version, time_bucket).
Signature computation, in order of preference:
- If the application supplies a stable error code or exception class plus top stack frames, hash those.
- Otherwise normalize the message: replace UUIDs, hex strings, numbers, IPs, emails, timestamps and quoted values with placeholders, collapse whitespace, then hash the template with a 64-bit hash.
- For hard cases, an offline log-template miner (a Drain-style parser) can merge templates and publish a mapping, applied as a later re-grouping.
Store a small table signature -> {template, first_seen, sample message, sample stack} so the UI can show something readable. Cap per-service signature cardinality (for example 10k) and route overflow into an other bucket, which protects against messages that embed unbounded unique text.
Common mistake: hashing the raw message. Every request ID then creates a new "error" and the counter becomes useless and expensive.
3. Write path
App SDK/agent -> Ingest API -> Partitioned log (Kafka)
-> Stream aggregator -> Counts store (time-series/OLAP)
-> Top-N cache
- Client side: the SDK or host agent can already batch and pre-aggregate locally for a few seconds, sending
(signature, count)pairs plus a sample. This alone often cuts volume by 10-100x. It must have a bounded buffer and drop with a counter metric when full, so the app is never blocked. - Ingest API: stateless, validates, normalizes if the client did not, and appends to the log. Partition by
hash(service, signature)so all events for one key land on one partition. This makes aggregation local and keeps hot keys visible. - Stream aggregator: keeps an in-memory map of
key -> countper tumbling window (10 s), flushes on window close plus a lateness allowance (for example 2 minutes), and writes increments to storage. A burst of one million identical errors becomes one increment per flush. - Backpressure and bursts: the log absorbs spikes (size it for several hours at peak). Autoscale aggregators on consumer lag. Hot-key splitting (add a random sub-shard suffix, merge at read or at the next rollup) handles a single signature that dominates a partition.
4. Storage and queries
Use a columnar or time-series store (ClickHouse, Druid or Pinot style), or Cassandra/Bigtable if you want a pure key-value layout.
Table error_counts_1m: (service, signature, region, version, minute) -> count, with the sort key (service, signature, minute).
- Range count for one error: sum the buckets in the range. A 24-hour query reads at most 1,440 rows per series.
- Time series: read the buckets directly, choosing 1-minute, 1-hour or 1-day tables based on the range so the number of points stays below about 1,000.
- Rollups: a background job (or the store's materialized views) rolls minute to hour to day, then TTL deletes the finer data.
- Top N in a recent window: two options. For exact answers, query
GROUP BY signature ORDER BY sum(count) DESC LIMIT Non the minute table, which is fine for a bounded window and a service filter. For the hot dashboard path, maintain a Space-Saving or Count-Min plus heap structure per window in the aggregator and publish the top 100 to a cache every few seconds. Label it approximate, with the exact query as a drill-down.
5. Correctness
- Delivery: at-least-once from the log. To make writes idempotent, the aggregator writes each flushed batch with a deterministic batch ID (partition, start offset, end offset); the store deduplicates on it, or the aggregator commits offsets and the writes transactionally. That gives effectively exactly-once counts.
- Failure recovery: on aggregator crash, a new instance resumes from the last committed offset and replays, with batch IDs preventing double application.
- Late events: accepted until the lateness bound. After that, either drop them with a metric or apply them through a correction path that adds to the already written bucket (additive counts make this safe).
- Accuracy statement: counts are exact after about 3 minutes, and the live top-N is approximate with a bounded error (for Count-Min, error at most epsilon times total, with high probability). Events lost at the client under extreme overload are reported as a separate
droppedcounter, so users know the lower bound.
6. Operating the platform
Monitor consumer lag, end-to-end freshness (event time vs. queryable time), drop counts at SDK and ingest, signature cardinality per service, store write latency and query p99. Alert on lag growth and on a sudden jump in distinct signatures, which usually means a normalization failure. Provide per-tenant rate limits so one noisy service cannot starve the rest.
7. Trade-offs
- Client-side aggregation saves bandwidth but delays data slightly and loses per-event timestamps within the window. This is acceptable at 10 s granularity.
- Heavier normalization gives better grouping but risks merging distinct errors. Keep samples so engineers can inspect and split signatures.
- Exact top-N is simpler to reason about but costly at scale. A sketch is cheap but approximate.
- Storing raw events enables reprocessing but costs a lot. Keep them only for a few days in cheap object storage.
Common mistakes
- Using the raw message as the key.
- One database write per error.
- Ignoring hot keys and cardinality explosions.
- Claiming exactly-once without explaining the idempotency mechanism.
- Not saying what happens with late data or what accuracy users should expect.