Microservice Event Stream & Kafka Synthesis
Synthetic Test Data Sprint β Day 3
Generate high-throughput temporal event streams, partition key hashing, simulated network jitter, and streaming watermark filters.
Event-driven microservices rely on Kafka or Kinesis topics where events arrive with partition keys, offsets, and non-deterministic network delays. In this lab, you build an event stream generator that simulates monotonic partition offsets, temporal jitter, and watermark filters.
The official reference codebase for Day 3 is hosted in the repository. Clone the repository and navigate to day-3-kafka-event-streams to run the working solution.
git clone https://github.com/777abhi/synthetic-test-data-roadmap.git
cd synthetic-test-data-roadmap/day-3-kafka-event-streamsInspect Event Stream Synthesis
Review partition key distribution, monotonic offset tracking, and watermark logic.
cat synthlab/event_streamer.py | head -45import unittest
from synthlab.event_streamer import EventStreamer, EventRecord
class TestDay3EventStreaming(unittest.TestCase):
def setUp(self):
self.streamer = EventStreamer(topic="orders.v1", partitions=4, seed=42)
def test_partition_mapping_is_deterministic(self):
p1 = self.streamer.partition_for_key("tenant_alpha")
p2 = self.streamer.partition_for_key("tenant_alpha")
self.assertEqual(p1, p2)
def test_watermark_filter_drops_late_records(self):
records = [
EventRecord("e1", "orders.v1", 0, 0, "k1", 10000, {"seq": 1}),
EventRecord("e2", "orders.v1", 0, 1, "k1", 15000, {"seq": 2}),
EventRecord("e3", "orders.v1", 0, 2, "k1", 11000, {"seq": 3}), # Late event
]
accepted, dropped = EventStreamer.apply_watermark_filter(records, watermark_delay_ms=2000)
self.assertEqual(len(dropped), 1)Execute Day 3 Tests
Run the event streaming and watermark test suite.
npm run test:day3- Engineered deterministic partition key hashing matching Kafka murmur/MD5 partition assignment.
- Simulated temporal jitter and late-arriving events for stream processing robustness.
- Implemented low-watermark threshold calculation to quarantine late data in streaming pipelines.
π§ Knowledge Check
What is the purpose of a watermark delay threshold in streaming event pipelines?