Project Workshop — Production Kafka System
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important…
- What you are building
- Architecture
- Acceptance criteria
- Suggested repository structure
- Build plan: vertical slices
Kafka · SSL · SASL · Kafka Connect · Prometheus · Grafana
Expected effort: 20–32 focused hours · Minimum meaningful tests: 24What you are building
This is a portfolio submission, not a copy-and-run tutorial. A reviewer must be able to clone it, configure it without guessing, execute the critical path, observe a deliberate failure, run the tests, and understand the most important design decision from the README.
Architecture
Critical interaction
Ownership table
| Boundary | Owns | Must not own |
|---|---|---|
| Interface | Parsing, protocol validation, identity extraction, status or presentation mapping | Core business invariants |
| Application/domain | Authorization inputs, state transitions, orchestration, transaction intent | Framework globals or raw transport objects |
| Repository/gateway | One persistence or external protocol, bounded retries, error translation | Product policy |
| Background/UI projection | Recoverable derived state and delivery progress | Hidden authoritative truth |
| Operations | Configuration, health, deployment, telemetry, recovery | Business decisions encoded only in dashboards |
Acceptance criteria
| ID | Required behavior | Evidence |
|---|---|---|
| AC-1.1 | at-most-once/at-least-once/exactly-once produces the specified behavior inside Exactly-once semantics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | idempotent producers produces the specified behavior inside Exactly-once semantics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | transactions: atomic read-process-write produces the specified behavior inside Exactly-once semantics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.4 | EOS Python transactional API produces the specified behavior inside Exactly-once semantics | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | SSL encryption + SASL (PLAIN/SCRAM-SHA-256) produces the specified behavior inside Security & monitoring | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | ACLs with kafka-acls.sh produces the specified behavior inside Security & monitoring | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | Prometheus JMX exporter produces the specified behavior inside Security & monitoring | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.4 | Grafana key metrics: consumer lag/under-replicated/latency produces the specified behavior inside Security & monitoring | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | JDBC source connector (PostgreSQL→Kafka) produces the specified behavior inside Kafka Connect | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | JDBC sink + S3 sink connectors produces the specified behavior inside Kafka Connect | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | connector JSON configuration produces the specified behavior inside Kafka Connect | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | REST API for connector management produces the specified behavior inside Kafka Connect | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | embedded library vs independent processing cluster produces the specified behavior inside Kafka Streams vs Flink | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | event-time windows and watermarks produces the specified behavior inside Kafka Streams vs Flink | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | local state stores and changelogs produces the specified behavior inside Kafka Streams vs Flink | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.4 | Flink checkpoints and savepoints produces the specified behavior inside Kafka Streams vs Flink | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.5 | choice by topology/operations/state/latency produces the specified behavior inside Kafka Streams vs Flink | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.1 | consumer lag age and growth produces the specified behavior inside Alert rule reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.2 | under-replicated partitions produces the specified behavior inside Alert rule reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.3 | offline partitions and ISR shrink produces the specified behavior inside Alert rule reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-5.4 | request latency and failed produce/fetch rate produces the specified behavior inside Alert rule reference | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
Suggested repository structure
1project/2├── src/{producer.py,consumer.py,models.py,handlers.py,idempotency.py}/3├── contracts/{schemas,retry-envelope}/4├── config/5├── tests/{unit,integration,rebalance,failure}/6├── compose.yaml7├── pyproject.toml8└── runbooks/Build plan: vertical slices
| Milestone | Capability | First implementation | Exit condition |
|---|---|---|---|
| 1 | Exactly-once semantics | at-most-once/at-least-once/exactly-once; idempotent producers; transactions: atomic read-process-write | Demonstration plus focused tests |
| 2 | Security & monitoring | SSL encryption + SASL (PLAIN/SCRAM-SHA-256); ACLs with kafka-acls.sh; Prometheus JMX exporter | Demonstration plus focused tests |
| 3 | Kafka Connect | JDBC source connector (PostgreSQL→Kafka); JDBC sink + S3 sink connectors; connector JSON configuration | Demonstration plus focused tests |
| 4 | Kafka Streams vs Flink | embedded library vs independent processing cluster; event-time windows and watermarks; local state stores and changelogs | Demonstration plus focused tests |
| 5 | Alert rule reference | consumer lag age and growth; under-replicated partitions; offline partitions and ISR shrink | Demonstration plus focused tests |
| 6 | Hardening and delivery | Security, recovery, telemetry, performance, documentation | Full acceptance suite and recorded demonstration |
For each milestone, first create a failing acceptance test or a reproducible command. Implement the thinnest path to an observable result, add the nearest durable invariant, inject one expected failure, and refactor only after evidence protects the behavior.
Reference vertical slice
1producer.init_transactions()2while True:3 records = consumer.consume(num_messages=100, timeout=1.0)4 if not records:5 continue6 producer.begin_transaction()7 try:8 for record in records:9 producer.produce("validated.v1", key=record.key(), value=validate(record.value()))10 producer.send_offsets_to_transaction(offsets_after(records), consumer.consumer_group_metadata())11 producer.commit_transaction()12 except Exception:13 producer.abort_transaction()14 raiseExpected result
1Output records and input offsets become visible atomically to read_committed consumers.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | producer.init_transactions() | Implements the next python statement in the example's data flow. |
| 2 | while True: | Repeats while the condition remains true; the body must make progress toward termination. |
| 3 | records = consumer.consume(num_messages=100, timeout=1.0) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 4 | if not records: | Evaluates the condition and enters this branch only when it is truthy. |
| 5 | continue | Implements the next python statement in the example's data flow. |
| 6 | producer.begin_transaction() | Implements the next python statement in the example's data flow. |
| 7 | try: | Defines failure translation or cleanup that must run around the protected operation. |
| 8 | for record in records: | Consumes the iterable one item at a time through the iterator protocol. |
| 9 | producer.produce("validated.v1", key=record.key(), value=validate(record.value())) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 10 | producer.send_offsets_to_transaction(offsets_after(records), consumer.consumer_group_metadata()) | Implements the next python statement in the example's data flow. |
| 11 | producer.commit_transaction() | Implements the next python statement in the example's data flow. |
| 12 | except Exception: | Defines failure translation or cleanup that must run around the protected operation. |
| 13 | producer.abort_transaction() | Implements the next python statement in the example's data flow. |
| 14 | raise | Stops the happy path with a deliberate exception carrying the boundary failure. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| Exactly-once semantics | EOS does not make an arbitrary HTTP call or database write exactly once. | Use Kafka EOS for Kafka-to-Kafka flows and idempotent sinks for external effects. |
| Security & monitoring | Slow processing beyond poll limits causes rebalances and duplicate work. | Commit only after the corresponding side effects are durable and make the handler idempotent. |
| Kafka Connect | A connector does not automatically solve source consistency, deletes, or sink idempotency. | Use Connect for well-supported integration patterns and manage schemas explicitly. |
| Kafka Streams vs Flink | Neither engine fixes bad keys, unbounded state, or undefined late-event policy. | Choose Streams for Kafka-centric topologies owned with an application, and Flink for large, stateful, event-time pipelines needing an operational processing cluster. |
| Alert rule reference | Averages hide affected partitions and tail failures; retry traffic can make throughput look healthy while user-visible latency collapses. | Alert on sustained tail latency or error-rate deviation together with queue time, ISR, disk, network, client timeouts, and consumer lag. |
Engineering checklist for this stack
- To do: assign stable message and operation identities
- To do: acknowledge only after the intended durable outcome
- To do: make handlers idempotent
- To do: bound retry and route terminal failures
- To do: monitor age, lag, duplicates, and stranded work
Test strategy
Implement at least 24 meaningful cases. A long list of shallow happy-path tests does not satisfy the requirement.
| Risk class | Minimum | Examples |
|---|---|---|
| Happy path and contract | 2 | Correct output, status/schema, durable state |
| Validation and boundaries | 2 | Empty, malformed, extreme, unsupported transition |
| Authorization or trust boundary | 1 | Missing identity, wrong tenant/role, injection or unsafe content |
| Failure and recovery | 2 | Timeout, retry, rollback, reconnect, dependency outage |
| Duplicate or concurrency | 1 | Same identity twice, racing update, redelivery |
| Performance and operations | 16 | Query bound, lag, p95, resource limit, telemetry |
Representative test scaffold
1def test_redelivery_has_one_logical_effect(harness):2 event = make_event(event_id="evt-1")3 harness.deliver(event)4 harness.crash_after_side_effect_before_commit()5 harness.deliver(event)6 assert harness.domain_effect_count("evt-1") == 17 assert harness.committed_offset_is_after(event)8
9def test_permanent_failure_reaches_dlt(harness):10 harness.deliver(make_invalid_event(event_id="evt-bad"))11 assert harness.dlt_envelope("evt-bad")["attempts"] >= 1Failure drills
- Stop the primary external dependency during the critical path. Capture the failure, cleanup, telemetry, and recovery.
- Repeat the same operation with the same stable identity. Prove one logical outcome or document why repetition is forbidden.
- Crash after durable state changes but before the response, acknowledgement, or projection. Re-run and reconcile.
- Submit the largest supported input and one slightly larger input.
- Remove one permission and prove denial without state change or information leakage.
- Roll back the change or restore the dependency, then run a smoke test and reconciliation check.
Performance experiment
State the dataset, payload distribution, concurrency, rate, duration, cache state, and resource limits before measuring. Publish p50, p95, p99, throughput, error rate, and the technology-specific correctness signal such as query count, consumer lag, duplicate effects, rendered updates, token cost, or recall. Change one variable at a time and retain raw output.
Submission package
- Complete source with a locked/reproducible environment.
- README.md with problem, architecture, setup, commands, configuration, assumptions, and trade-offs.
- Acceptance and risk-focused tests with a short explanation of what mocks intentionally do not cover.
- One design record explaining the most consequential choice and a rejected alternative.
- Security notes, sample non-secret configuration, and cleanup commands.
- A demonstration record: terminal transcript, screenshots, trace, query plan, or metrics dashboard.
- A 5–8 minute walkthrough following input → validation → state → failure → evidence.
Grading rubric
| Dimension | Weight | Full-credit evidence |
|---|---|---|
| Product behavior | 25 | Acceptance criteria pass through real public boundaries |
| Architecture and ownership | 20 | Responsibilities and state authority are explicit |
| Tests and recovery | 20 | Important negative, duplicate, concurrent, and outage cases pass |
| Security and data correctness | 15 | Least privilege, validation, constraints, and secret handling are demonstrated |
| Performance and operations | 10 | Reproducible measurement, useful telemetry, and rollback/recovery |
| Documentation and explanation | 10 | A new reviewer can reproduce and defend the result |
Mastery check
How well can you recall this?
Finished this lesson?