Project Workshop — Order System + Schema Registry
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 · Schema Registry · Avro · confluent-kafka
Expected effort: 15–24 focused hours · Minimum meaningful tests: 12What 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 | Producer/Consumer/AdminClient produces the specified behavior inside confluent-kafka & kafka-python | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.2 | AIOKafka for async consumers produces the specified behavior inside confluent-kafka & kafka-python | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-1.3 | delivery reports and callbacks produces the specified behavior inside confluent-kafka & kafka-python | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.1 | retry topic pattern (topic→retry→dlt) produces the specified behavior inside Error handling & DLQ | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.2 | Dead Letter Topic with error envelope produces the specified behavior inside Error handling & DLQ | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-2.3 | DLT alerting strategy produces the specified behavior inside Error handling & DLQ | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.1 | Avro schema definition produces the specified behavior inside Schema Registry & Avro | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.2 | compatibility modes: BACKWARD/FORWARD/FULL produces the specified behavior inside Schema Registry & Avro | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.3 | confluent-kafka + fastavro integration produces the specified behavior inside Schema Registry & Avro | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-3.4 | schema evolution: adding optional fields produces the specified behavior inside Schema Registry & Avro | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.1 | synchronous flush vs asynchronous delivery produces the specified behavior inside Producer & consumer modes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.2 | JSON serializer vs Avro serializer produces the specified behavior inside Producer & consumer modes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.3 | transactional producer lifecycle produces the specified behavior inside Producer & consumer modes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.4 | auto.offset.reset earliest/latest/error produces the specified behavior inside Producer & consumer modes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.5 | sync vs async commit callbacks produces the specified behavior inside Producer & consumer modes | Automated assertion, reproducible command, plan, trace, metric, or accessible browser check |
| AC-4.6 | subscribe assignment vs manual assign produces the specified behavior inside Producer & consumer modes | 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 | confluent-kafka & kafka-python | Producer/Consumer/AdminClient; AIOKafka for async consumers; delivery reports and callbacks | Demonstration plus focused tests |
| 2 | Error handling & DLQ | retry topic pattern (topic→retry→dlt); Dead Letter Topic with error envelope; DLT alerting strategy | Demonstration plus focused tests |
| 3 | Schema Registry & Avro | Avro schema definition; compatibility modes: BACKWARD/FORWARD/FULL; confluent-kafka + fastavro integration | Demonstration plus focused tests |
| 4 | Producer & consumer modes | synchronous flush vs asynchronous delivery; JSON serializer vs Avro serializer; transactional producer lifecycle | Demonstration plus focused tests |
| 5 | 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
1def consume(consumer, repository, producer):2 while True:3 message = consumer.poll(1.0)4 if message is None:5 continue6 if message.error():7 raise KafkaException(message.error())8 event = deserialize_avro(message.value())9 try:10 repository.apply_once(event["event_id"], event)11 except PermanentDomainError as exc:12 producer.produce("orders.dlt.v1", key=message.key(), value=error_envelope(message, exc))13 consumer.commit(message=message, asynchronous=False)Expected result
1The handler applies each event identity once, routes permanent failures to a DLT, then commits the processed offset.Code reading
| Line | Code | Explanation |
|---|---|---|
| 1 | def consume(consumer, repository, producer): | Defines a function; its parameters form the explicit input boundary. |
| 2 | while True: | Repeats while the condition remains true; the body must make progress toward termination. |
| 3 | message = consumer.poll(1.0) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 4 | if message is None: | 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 | if message.error(): | Evaluates the condition and enters this branch only when it is truthy. |
| 7 | raise KafkaException(message.error()) | Stops the happy path with a deliberate exception carrying the boundary failure. |
| 8 | event = deserialize_avro(message.value()) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 9 | try: | Defines failure translation or cleanup that must run around the protected operation. |
| 10 | repository.apply_once(event["event_id"], event) | Implements the next python statement in the example's data flow. |
| 11 | except PermanentDomainError as exc: | Defines failure translation or cleanup that must run around the protected operation. |
| 12 | producer.produce("orders.dlt.v1", key=message.key(), value=error_envelope(message, exc)) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
| 13 | consumer.commit(message=message, asynchronous=False) | Computes or receives a value and binds it for the next step; the referenced object remains separate from the name. |
Risk register
| Area | Failure to reproduce | Required design response |
|---|---|---|
| confluent-kafka & kafka-python | Calling flush after every message destroys batching. | Treat callback errors as delivery outcomes and close consumers gracefully. |
| Error handling & DLQ | A DLT without ownership, retention, and replay policy is only a data graveyard. | Alert, inspect, and provide a controlled replay tool. |
| Schema Registry & Avro | Changing meaning without changing a field name is still a breaking semantic change. | Add optional fields with defaults and test producer-consumer compatibility in CI. |
| Producer & consumer modes | A JSON serializer is not a DRF serializer, and manual assignment does not participate in consumer-group rebalancing. | Use versioned schemas, stable keys, bounded polling loops, explicit shutdown, and idempotent side effects before advancing recoverable progress. |
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 12 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 | 4 | 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?