Appendix F: Deploying event-driven services on minikube
A deployment stops consumers that own partitions. A stop and restart delays records, a rolling update repeats some, a breaking schema change loses them silently, and a blue-green cut-over needs the old group's offsets. Each is run on minikube under a producer that numbers every record.
A consumer in a group owns partitions. Stopping it hands them to another member or to nobody, a record it read and had not committed can be read again, and a record it could not store may be skipped, leaving only an error line in the log. Whether a change loses records, repeats them or only delays them depends on how the pods are replaced and on whether the new code reads what the old code wrote.
The strategies below run on a minikube cluster with two existing images, unchanged: a notification-service, whose group, protocol and client id come from the environment, and an order-service that answers POST /orders. A producer Job sends numbered records (O-41000 and up) at a fixed rate, so a record that is missing, repeated or read by two groups is found by its id.
Learning objectives
- Predict whether a deployment strategy delays, repeats, or drops records for a given service shape
- Apply the expand, migrate, and contract sequence to a schema change the old and new code cannot both read
- Read a cut-over’s offset export and import to judge what a blue-green rollback resumes from
- Recognize why consumer lag alone cannot reveal a broken insert on a renamed field
Why this matters
The deployment strategy decides whether a release delays, repeats, or drops records, and skipping expand, migrate, and contract for a schema change can lose rows while logging only one error line. When a dashboard watches consumer lag alone, it can report healthy while an insert fails on a renamed field, because the offset commits and the lag reads zero. Match the strategy to whether a service owns a consumer group or sits behind a load balancer, and a routine release stops losing data a customer finds before anyone else does.
Stop and restart
The Deployment strategy Recreate kills every existing pod before it creates new ones (Kubernetes, Deployments). For a consumer group it has the fewest moving parts: one membership ends, another begins, and Kafka keeps the records in between.
Nothing is lost, because the topic holds what the producer sent while no consumer ran. The stop costs time: the backlog grows for as long as the new pods need to start.
New pods rejoin the group, read from the committed offset and drain the backlog faster than it grew. The offset trails the last processed record, because the Kafka client commits on a timer, the Camel Kafka default. A record processed after the last commit can be processed again, and the attempts column of the notification table reads 2 for it. How many repeat depends on timing and can be none. An idempotent consumer makes the repeat harmless.
Choose a stop and restart when the old and the new version must not run together, or when a gap of one pod start is acceptable.
Rolling update of a consumer group
A rolling update replaces pods in steps. With maxSurge: 1 and maxUnavailable: 0 the Deployment starts a new pod, waits for it to be ready, then removes an old one, so the Deployment never has fewer than three available pods.
strategy:
type: RollingUpdate
rollingUpdate: {maxSurge: 1, maxUnavailable: 0}
Each start and each stop changes the group’s membership, and a membership change is a rebalance. Partitions move between members, and the member that gives one up has committed only as far as its last commit, so the records after that point can go to the new owner again.
Under the classic group protocol the members take part in the rebalance. With the consumer protocol of KIP-848 the group coordinator on the broker drives it, declaring an assignment and reconciling each member toward it (Apache Kafka, KIP-848). The notification-service selects the protocol with GROUP_PROTOCOL, and the image runs under either one unchanged. Neither protocol guarantees that no record is repeated: a record read and not yet committed when its partition moves is delivered again, so the repeat is bounded by what was processed since the last commit at each move.
A readiness probe decides when the Deployment counts a new pod as available and lets the rollout continue. The pod joins the group when the application starts, whatever the probe reports, and maxUnavailable: 0 keeps capacity from dropping.
Rolling update of a service under requests
A service behind a Kubernetes Service has no group to rebalance. The risk is at the edge: a request that reaches a pod while it is being removed.
The order-service answers POST /orders and publishes one event per accepted order. During a rolling update with a readiness probe, requests in flight on a pod that is removed can fail at the connection level, as a reset or a timeout, and the client has to retry them. No request was answered with a 5xx status. The publish happens before the response, so a failed request may already have left its event, and the client cannot tell. The retry tells it: 409 on the id of an accepted order, which publishes nothing more, or 201 for one that was not. After every retry, each order has exactly one event.
Quarkus can drain running requests: quarkus.shutdown.timeout waits for them, and quarkus.shutdown.delay keeps serving while the readiness probe reports down, but only when quarkus.shutdown.delay-enabled is true, a build-time property that defaults to false (Quarkus, all configuration). The Deployment sets none of them, because the image stays as built. The guarantee does not depend on them: it rests on the client’s retry and on the id that makes the retry safe.
A breaking schema change
The notification-service reads orderId. A producer that renames it to orderRef ships a new version of the contract, and the consumer of the old version cannot know.
The record is read, the insert fails on the missing value, Camel logs Failed delivery and the route moves on. The offset is committed, the lag is zero and the row does not exist. A dashboard on lag stays green. Plain JSON on a topic has no gate between producer and consumer: the broker accepts whatever the producer sends.
An additive change takes two compatible steps and a third that removes, the expand and contract sequence that Danilo Sato describes as Parallel Change. First the producer expands: it sends both orderId and orderRef. The old consumer reads the field it knows and ignores the other, and consumers of the new version read orderRef. Every record is stored.
Then each consumer is deployed to read orderRef, one of the strategies above. The producer contracts last, when it stops sending orderId, and only once no consumer still reads it.
When a change cannot be made compatible, the new shape gets a new topic. A migration consumer reads the old topic, converts each record and writes it to the new one. Producers move to the new topic, consumers follow, and the old topic is retired when its retention has passed.
It costs a topic, a consumer and a window with two sources of truth, and it is drawn, not run, because the notification-service reads fixed topics.
Blue-green consumers: cut-over and rollback
Blue-green runs the new version beside the old one and moves the load in one step. For consumers the unit is the consumer group. Blue is the live Deployment under group notify-blue. Green is a second Deployment of the next version under its own group, notify-green, at zero replicas.
A new group has no offsets, so green would replay the topic or skip what blue had not yet read. The cut-over gives green blue’s position instead. Kafka resets the offsets of a group only while its consumers are inactive, and accepts a CSV file of values (Apache Kafka, basic operations). The target group can be new: it needs no members and no earlier offsets.
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group notify-blue \
--reset-offsets --to-current --all-topics --dry-run --export > offsets.csv
kafka-consumer-groups.sh --bootstrap-server localhost:9092 --group notify-green \
--reset-offsets --from-file offsets.csv --execute
The export has one topic,partition,offset line per partition and no header. The cut-over is four steps: scale blue to zero and wait for its group to be Empty, which its members reach by leaving the group on shutdown; export; import; scale green up.
Nothing goes missing, because green starts where blue’s commits ended. Records can be read twice: blue processed records after its last commit, green starts at that commit, and both groups store them. The overlap is bounded by what blue processed in its last commit interval, and it can be zero.
Rollback is the same four steps the other way: stop green, copy green’s offsets to blue’s group, start blue. Blue’s group exists and holds older offsets, and the import replaces them, so blue resumes after what green processed. Without the copy a new group replays the topic and an old group resumes at its old position, reading everything since the cut-over again.
Build, run, observe
examples/_k8s/cluster.sh up
cd examples/af-deploying-event-driven-services
./verify.sh
verify.sh deploys the two images unchanged and replaces them under a producer at a fixed rate: a stop and restart, a rolling update, a rolling update under HTTP requests, a breaking and a compatible schema change, a cut-over and a rollback. Watch the rows per id and the group offsets. It ends with 30/30 checks passed.
Try one change and rerun:
GROUP_PROTOCOL=classic ./verify.sh(demo code): the rolling update runs on the classic protocol, and the group is no longer a consumer-protocol group.OFFSET_COPY=off ./verify.sh(demo code): green starts at the beginning of the topic and blue resumes from its old offsets, so the groups process the same ids again.
When not to use it
Every strategy here delivers at least once. A consumer that cannot tolerate a repeat needs an idempotent consumer or Kafka transactions first, and no deployment strategy replaces either.
Blue-green consumers pay for two groups, a copy step and a stop between them. When the old and the new version can read the same topic together, which is true of every compatible change, a rolling update does the same work with no copy. When a consumer is stateless and a delay of one pod start is acceptable, the stop and restart is the least to operate.
A client of a rolling service has to expect failed requests, because a connection open to a pod that is removed can be reset. It retries, and the service needs a way to tell a retry from a new request.
Common pitfalls
- Trusting consumer lag as the only deployment health signal: a renamed field can make every insert fail while the offset still commits and lag reads zero.
- Running a breaking schema change in one step instead of expand, migrate, and contract: the old consumer’s insert fails on the field it no longer finds, and the row is lost with no trace in a lag dashboard.
- Skipping the offset export before a blue-green cut-over or rollback: the target group then replays the topic from the start or resumes from a stale position, reading everything since the switch again.
- Assuming a rolling update needs no retry handling at the client: a pod being removed can reset a connection in flight, and a request that already published its event before the reset looks identical to one that never did.
🤖 Explore with your agent “In examples/af-deploying-event-driven-services, run verify.sh with OFFSET_COPY=off, then query notifications.notification for the groups notify-blue and notify-green in the id range O-51000 to O-54999. List the ids both groups hold and say why green re-read them. Then read group_offsets_copy in examples/_k8s/lib.sh and state what it exports from the source group, what it imports into the target, and why the source group must have no members.” Check: with OFFSET_COPY=off the two groups share every id blue had processed before the cut-over and no id is missing; with the copy they share only the records after blue’s last commit, at most what blue wrote in its last commit interval.
References
- Kubernetes, Deployments (the
RecreateandRollingUpdatestrategies,maxSurgeandmaxUnavailable) - Apache Kafka, KIP-848: The Next Generation of the Consumer Rebalance Protocol (the group coordinator drives assignment)
- Apache Kafka, Basic Kafka operations (resetting consumer group offsets: inactive consumers,
--from-file,--execute) - Quarkus, All configuration (
quarkus.shutdown.timeout,quarkus.shutdown.delay) - Adam Bellemare, Building Event-Driven Microservices, 2nd ed., O’Reilly, 2025, chapter 21: Deploying Event-Driven Microservices
- Danilo Sato, Parallel Change, martinfowler.com, 2014: expand, migrate and contract
- Event notification: the order-service
- Optimizing subscribers: the notification-service and its consumer settings
- Idempotent consumer and inbox: making a repeat harmless
- Exactly-once with Kafka transactions: transactions
- Schema evolution and upcasting: schema evolution
- Strimzi and KRaft: the cluster