Design a system like SignalFx/Splunk
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2024-03-16
Problem Statement
Modern organizations need observability systems to collect, store, query, visualize, and alert on large volumes of metrics, logs, and traces. Systems like Splunk and SignalFx ingest terabytes of machine-generated data daily, index it in near-real time, and allow low-latency queries, dashboards, and alerts.
We need to design a metrics & log analytics platform that can:
•Ingest high-velocity, high-volume streams of metrics/logs from servers, apps, IoT devices.
•Store them efficiently with time-series optimizations.
•Allow real-time querying with filters (e.g., keyword, time-range).
•Provide visualizations & dashboards for end-users.
•Support alerts based on thresholds or anomalies.
✅ Functional Requirements
1.Ingestion
•Accept logs/metrics from multiple sources (agents, APIs, streams like Kafka).
•Support both structured metrics (time-series data points) and unstructured logs.
•Handle high throughput (millions of events/sec).
2.Storage
•Efficiently store time-series metrics (e.g., CPU usage every second).
•Index logs for keyword & contextual search.
•Provide compression and tiered storage (hot/warm/cold).
3.Querying
•Allow queries by time window, keywords, tags/labels.
•Support aggregations (avg, p95 latency, error counts).
•Low-latency response for recent data.
4.Visualization
•Dashboards with charts, heatmaps, anomaly detection.
•Customizable per team or system.
5.Alerts
•Define rules (static thresholds, rate of change, anomaly detection).
•Send alerts via email, Slack, PagerDuty.
•Support real-time streaming evaluation (no delays).
❌ Non-Functional Requirements
•Scalability: Support petabytes of historical logs, millions of metrics per second.
•Latency: Ingestion to query latency < 2–3 seconds (near real-time).
•Availability: 99.99% (observability system must be highly reliable).
•Consistency: Eventual consistency acceptable in query results.
•Cost Optimization: Tiered storage (SSD for hot, S3/HDFS for cold).
🧱 System Components
1.Data Collectors/Agents
•Installed on hosts/containers to forward logs/metrics.
•Use protocols like gRPC, HTTP, or Kafka producers.
2.Ingestion Layer
•Message queues (Kafka/Pulsar) for buffering.
•Stream processors (Flink/Samza/Spark Streaming) for enrichment, filtering.
3.Storage Layer
•Metrics: Time-Series DB (TSDB) like M3DB, Prometheus-like storage, or custom columnar store.
•Logs: Distributed indexing store (e.g., ElasticSearch, ClickHouse, Splunk-like custom index).
•Tiering: Hot (SSD), Warm (HDD), Cold (object storage like S3).
4.Indexing & Query Engine
•Full-text search index for logs (inverted index, keyword trees).
•Pre-aggregations for metrics (downsampling older data: 1s → 1m → 1h buckets).
•Query router that distributes queries across shards.
5.Visualization & API Layer
•REST/GraphQL API for queries.
•Dashboard builder for charts/graphs.
•Real-time UI updates (WebSockets).
6.Alerting System
•Rule engine evaluating streams.
•Anomaly detection models (ML-based).
•Notification integrations.
🔄 Example Flow
1.Application emits log:
1
2[2025-08-25 14:32:10] ERROR ServiceX Timeout in DB query1.Agent forwards log → Kafka → Stream processor tags log with metadata (host, service).
2.Log stored in ElasticSearch/ClickHouse cluster (with index on timestamp + keywords).
3.User queries "ServiceX AND ERROR last 1h" → Query Service fans out query to shards → merges results → returns in <2s.
4.Alert engine detects >100 errors in last 5 mins → triggers PagerDuty notification.
⚖️ Trade-offs & Design Considerations
•Storage choice: Columnar DB (fast aggregations, good compression) vs inverted index (flexible text search).
•Real-time vs Batch: Stream processing for hot data, batch jobs for historical queries.
•Cost optimization: Cold storage trade-off (cheap but higher query latency).
•Query optimizations: Pre-aggregated rollups for metrics vs on-the-fly compute.
•Multi-tenancy: Isolate customer queries & data securely.
🧪 Open Discussion Points
•How to design query planner that balances across time-series DB and log index?
•Should alerts run on raw logs or pre-aggregated metrics?
•How to handle schema-less log ingestion (JSON vs plain text)?
•Should we support cross-correlation queries (e.g., logs + metrics + traces in one query)?
👉 This problem tests distributed storage design, indexing, streaming pipelines, query optimizations, and observability concepts — making it a core HLD interview problem.