Bird
Raised Fist0

Count-Min Sketch for Frequency Estimation at Scale

HLDmediumInterview freq: medium
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/6
Kafka Cluster

Receive event stream

Kafka ingests high-volume event data for frequency counting

Protocol:Kafka Stream
BeforeKafka topic partition has no new events
AfterKafka topic partition contains new event appended
Stream Processing (Apache Flink)

Consume Kafka events and update CMS

Flink processes events, updates Count-Min Sketch counters

Protocol:Kafka Stream
BeforeCMS counters in Redis reflect previous counts
AfterCMS counters in Redis incremented for new events
Count-Min Sketch Updater Store (Redis Cluster)

Store updated CMS counters

Redis stores updated CMS data structure with low latency

Protocol:Redis SET
BeforeCMS counters in Redis reflect old counts
AfterCMS counters in Redis reflect updated counts after Flink processing
Query API Server

Receive frequency query and fetch CMS data

API server queries Redis for CMS counters to estimate frequency

Protocol:Redis GET
BeforeQuery API Server has no cached CMS data for requested key
AfterQuery API Server retrieved CMS counters from Redis
Query API Server

Respond to client with frequency estimate

API server computes frequency estimate from CMS and returns result

Protocol:HTTP/REST
BeforeFrequency estimate not yet computed
AfterClient receives frequency estimate response
Monitoring & Alerting (Prometheus + Grafana)

Collect metrics from Flink and Redis

Prometheus scrapes metrics; Grafana visualizes system health

Protocol:Prometheus scrape
BeforeMetrics data not yet collected for current interval
AfterMetrics data available for alerting and dashboards
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────────────────────┐
│         Kafka Cluster          │
│  (Distributed message queue)  │
└───────────────┬───────────────┘
                │ Kafka Stream
                ▼
┌───────────────────────────────┐
│ Stream Processing (Flink)     │
│ (Processes streams, updates   │
│  CMS)                        │
└───────────────┬───────────────┘
                │ Redis SET (CMS update)
                ▼
┌───────────────────────────────┐
│Count-Min Sketch Updater Store │
│      (Redis Cluster)           │
│ (Stores CMS data structure)   │
└───────────────┬───────────────┘
                │ Redis GET (Query)
                ▼
┌───────────────────────────────┐
│       Query API Server         │
│ (Handles frequency queries)    │
└───────────────┬───────────────┘
                │ HTTP/REST Query
                ▼
┌───────────────────────────────┐
│Monitoring & Alerting           │
│(Prometheus + Grafana)          │
│(Metrics from Flink & Redis)   │
└───────────────────────────────┘

This architecture uses Kafka as a durable, scalable event ingestion layer feeding Apache Flink for real-time stream processing. Flink updates the Count-Min Sketch data structure stored in Redis, which acts as a low-latency cache for frequency estimates. The Query API Server handles client frequency queries by reading CMS counters from Redis, enabling fast approximate frequency estimation without heavy computation. Monitoring via Prometheus and Grafana ensures system health visibility by collecting metrics from Flink and Redis. The vertical flow from Kafka through Flink to Redis and then to the Query API Server highlights the separation of ingestion, processing, storage, and query responsibilities, enabling scalable frequency estimation at high throughput.

Primary Focus

✓

Practice

(1/5)
1. A system must ingest 1 million events per second with guaranteed ordering per user session and durable storage. Which component best handles this ingestion requirement?
easy
A. Use Redis Pub/Sub for low latency event streaming
B. Use a relational database with batch inserts for durability
C. Use Kafka with partitioning keyed by user session ID
D. Use a simple HTTP endpoint with in-memory queueing

Solution

  1. Step 1: Identify Kafka's role in ingestion

    Kafka supports high-throughput ingestion with partitioning by user session ID, ensuring ordering per session and durability via log storage.
  2. Step 2: Eliminate alternatives

    Relational DB batch inserts can't handle 1M events/sec with ordering guarantees; Redis Pub/Sub lacks durability and ordering guarantees; HTTP with in-memory queueing risks data loss and no ordering guarantees.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Kafka partitions keyed by session ensure ordering and durability [check]
Hint: Kafka partitions preserve ordering per key [check]
Common Mistakes:
2. A customer support bot must handle 10,000 concurrent user queries with minimal latency and ensure fallback to human agents when intent classification confidence is low. Which component is best suited to manage the fallback routing reliably?
easy
A. A relational database storing fallback requests synchronously
B. An in-memory cache storing fallback intents temporarily
C. A REST API endpoint directly invoking human agent notification
D. A message queue system decoupling intent classification from fallback processing

Solution

  1. Step 1: Identify fallback routing requirements

    The fallback must be reliable and decoupled from real-time intent classification to avoid blocking user queries.
  2. Step 2: Evaluate component suitability

    A message queue decouples processing, enabling asynchronous fallback handling and retry mechanisms. Relational DB synchronous writes (A) cause latency. REST API direct calls (C) block the main flow. In-memory cache (D) lacks durability and reliability.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Message queue decouples and buffers fallback reliably [check]
Hint: Decouple fallback with queues for async reliability [check]
Common Mistakes:
3. In a PACELC-based system, at step 4 the Write Coordinator checks the network partition status before committing a write. What happens if the network is partitioned but latency is prioritized?
easy
A. The Write Coordinator rejects the write to maintain consistency
B. The Write Coordinator waits for all replicas to acknowledge before committing
C. The Write Coordinator commits locally and replicates asynchronously later
D. The Write Coordinator redirects the write to a different data center

Solution

  1. Step 1: Trace Write Coordinator behavior at Step 4

    When partitioned and latency prioritized, writes commit locally without waiting for replicas.
  2. Step 2: Understand asynchronous replication impact

    Local commit allows low latency; replication happens later, risking temporary inconsistency.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Local commit + async replication -> low latency under partition [check]
Hint: Local commit first, replicate later under partition and latency [check]
Common Mistakes:
4. For a mobile client calling a flaky backend service, which approach best balances responsiveness and failure isolation?
medium
A. Use synchronous calls with retries and exponential backoff
B. Rely on client-side caching to avoid backend calls during failures
C. Implement a circuit breaker with a short timeout and fallback response
D. Use a message queue to buffer requests and process asynchronously

Solution

  1. Step 1: Evaluate synchronous retries (A)

    Retries increase latency and risk cascading failures, bad for mobile responsiveness.
  2. Step 2: Compare asynchronous queue (C) and caching (D)

    Queues add delay and complexity; caching avoids calls but may serve stale data, not ideal for dynamic data.
  3. Step 3: Circuit breaker with short timeout and fallback (B)

    Provides quick failure detection, prevents cascading failures, and returns fallback to maintain responsiveness.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Circuit breaker with fallback balances isolation and responsiveness [check]
Hint: Circuit breaker with fallback keeps mobile responsive and isolated [OK]
Common Mistakes:
5. If the metrics aggregation service fails to update the error budget in real time, what is the most likely failure observed by the alerting system?
medium
A. Alerts trigger randomly due to inconsistent error count aggregation across nodes
B. Alerts never trigger because the error budget appears full and no burn rate is detected
C. Alerts trigger too frequently due to stale error budget values being reset to zero
D. Alerts show delayed notifications but eventually catch up after service recovery

Solution

  1. Step 1: Understand failure impact on error budget updates

    If aggregation service fails partially, inconsistent error counts across nodes cause alerting to behave erratically.
  2. Step 2: Eliminate other failure modes

    Resetting to zero (A) is unlikely without explicit reset; no alerts (B) implies total failure, not partial inconsistency; delayed alerts (D) imply buffering, not aggregation failure.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Aggregation failure -> inconsistent counts -> random alert triggers [check]
Hint: Aggregation failure causes inconsistent counts, leading to random alerts [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard