Event Streaming LabPython · Bytewax

Chapter 7 · Reading

Choose a streaming architecture

A work queue, a broadcast and a retained history solve different problems.

Prerequisites Read a partitioned log and Give consumers their own position. Find chapters in the course contents.

What you’ll learn

Choose how to send, retain and process events. Use each consumer’s needs for replay, response time and safe retries.

The situation

Checkout needs a stock decision now. Finance needs a complete sales history tomorrow. Marketing wants an email once. Putting all three behind one queue and calling the system event driven hides their different requirements. Start by stating the questions and failure boundaries each consumer must defend.

Commands, events and ownership

A command requests an action and can be rejected: reserve stock, charge a payment, send a message. An event records an accepted fact such as OrderPlaced. A consumer of an event may still fail to apply its own effect. Keep the event’s identity separate from its entity key, correlation ID and causation ID; each answers a different question about a record.

Name the authority for facts and versions. A consumer that sees two addresses cannot invent which is authoritative merely from arrival order. Define schema and semantic units, event versus observation timestamps, ownership and deletion rules before choosing a partition key. An immutable record does not make its interpretation or every derived view immutable.

Choose a delivery shape

A competing-consumer work queue assigns work among workers; it does not necessarily retain a replayable history for future independent readers. Pub/sub distributes messages to subscribers under its own retention and acknowledgement contract. A retained partitioned log gives independent readers positions and a replay horizon, while ordering remains scoped to a partition. These shapes can be combined, but their guarantees are not interchangeable.

Map an independent requirement to an independent consumption/effect boundary. Audit and a live dashboard may read the same retained history with different lag and retention needs. An email service still needs stable identities and an idempotent or reconciled effect even if its source is replayable. More consumers do not automatically provide more source ordering or shared state ownership.

Worked case

This worked case uses an example written for the course.

RequirementUseful shapeKey decisionEvidence still needed
Reserve stock nowCommand/requestAuthority and rejectionTimeout and unknown-outcome handling
Audit every retained salePartitioned log + independent readerRetention and identityCompleteness across failure/replay
Current shop totalKeyed projection/windowUpdate and lateness policySource/state/sink consistency
Send receipt emailEffecting consumerIdempotency identityDuplicate and unknown receipt reconciliation

Pick the processing pattern deliberately

Use stateless map/filter for independent transformations. Use flat-map when one input expands into several outputs and budget for that amplification. Keyed state answers questions involving history; windows and expiry choose which history remains relevant. A join requires an explicit relationship and output multiplicity. Sequence and absence patterns need a match/reset/clock policy, not just a convenient filter.

Prefer one clearly specified transformation contract across live and bounded replay paths. A historical batch implementation and a separate live implementation can drift on units, deletes, late records and identity. Reusing semantics does not imply identical execution mechanics. Record which stages require replayable input, which can be rebuilt, and which external effects cannot simply be repeated.

Review the topology as a set of contracts

Draw producers, source partitions, state owners, replay ranges and sinks separately. For every arrow, name payload bytes, order scope, acknowledgements, retry owner and backpressure behavior. For every stateful node, name its key, retention, checkpoint and rebuild procedure. Put latency and completeness budgets beside the actual query boundary rather than beside a framework logo.

A sound design can intentionally provide different answers at different times: a fast provisional dashboard, a corrected analytical view and an audited financial ledger. Make that distinction visible to consumers. Calling every output exactly once, real time or final conceals decisions that should instead be stated and tested.

Think it through

Design the first topology for a provisional dashboard, an audit reader and receipt emails. Which data can they share, and which acknowledgements or retry decisions must remain independent?

Show hints
  1. Hint 1

    A shared event history does not force a shared consumer position.

  2. Hint 2

    A query projection and an irreversible email effect have different replay contracts.

  3. Hint 3

    Name the record that proves each effect became visible.

Show explanation

Share a versioned, identified event contract and retained source where appropriate. Give independent readers their own progress and lag budgets. Maintain the dashboard as a defined projection, preserve audit history under its retention contract, and isolate email effects behind stable request identities and receipt/reconciliation logic. Verify failures at each acknowledgement boundary; source replay alone does not make external effects safe.

How frameworks implement this

Kafka provides a partitioned retained log with configurable broker/client semantics. Bytewax supplies processing operators and recovery interfaces. Flink and Spark offer their own execution, progress and state contracts. Work queues, brokers and processing engines are separate roles; this reading does not claim that any one product implements the entire architecture automatically.

ReferencesPrimary sources for this chapter’s design case

Use these guides to check the framework or protocol contract discussed in this chapter. Moving “stable” or “current” guides can describe a different release; check the version used by your deployment. These readings do not execute the distributed frameworks they compare.

This mark tracks what you’ve read.