Design a Kafka message filtering strategy that scales horizontally.

Instruction: Outline a system design for efficiently filtering messages in a Kafka stream at scale.

Context: Candidates must showcase their ability to design scalable Kafka solutions, focusing on filtering large volumes of messages in real-time.

Updated

Official answer

Use a Kafka Streams application to read an input topic, validate records, evaluate a predicate and write accepted events to an output topic. A separate routing topic is optional; add one only when it serves a distinct contract or consumer need.

For example, an order-quality stream may accept events whose status is paid and whose amount is positive. Define null, malformed and unknown-version handling explicitly. Keep rejected-record counts and, when appropriate, a restricted quarantine path rather than silently losing required work.

Deploy instances with the same application ID so Streams distributes tasks. Source partitions and topology structure constrain parallelism; adding instances beyond runnable tasks will not create more useful work. Preserve keys for per-entity order, or deliberately repartition if stateful filtering requires another key. A hot key and slow external dependency need separate treatment.

Version the filtering rules and specify whether replay uses historical or current rules. If rules are distributed dynamically, define their activation boundary so mixed instances do not make unexplained decisions. Stateful rules need bounded state, retention and restoration planning.

Consumer-group assignment gives ownership, not an automatic exactly-once business guarantee. Select the Streams processing guarantee for Kafka output/state/progress, and handle external effects separately. Test rule boundaries, replay, instance loss and recovery; monitor acceptance/rejection counts, completion age, errors and restoration time.

Streams filters and grouping, Streams runtime settings

Related Questions