Expand - Migrate - Contract
Idea
A change that would require more than one component to be deployed AT THE SAME TIME is split into multiple changes, each of which can be deployed independently.
Motivation
With Continuous Delivery, components must be independently deployable; changes that require coordinated, simultaneous deployment of multiple components must be split into compatible steps.
When to apply which strategy
Whenever possible, an evolutionary Expand/Migrate/Contract strategy without a new major version should be used!
- REST APIs can in many cases be extended in a backward-compatible way: Evolution and Versioning of REST APIs
- Messaging interfaces can, thanks to Avro, often be extended in a compatible way: Evolution of Messages
Procedure for EMC with a new, incompatible major version
The procedure is always the same:
| Step | Description |
|---|---|
| EXPAND | The provider offers a new interface |
| MIGRATE | The consumers (1..N) migrate to the new interface |
| CONTRACT | The provider removes the old, no-longer-used interface |
The following illustrates the procedure for the typical interface types. The procedure is always identical, regardless of the interface type.
REST API
Command
- Not Avro-compatible:
- New major version of the Command
- New name of the Avro schema
- New names of the Java classes
- New major version of the Command
Event
- Not Avro-compatible:
- New major version of the Event
- New name of the Avro schema
- New names of the Java classes
- New major version of the Event
Expand-Migrate-Contract & Messaging
The following recommendations should be observed when applying Expand-Migrate-Contract in the context of jEAP messaging.
For a discussion of the recommended migration strategies, see Evolution of Messages.
EMC Message Evolution
With this strategy, incompatible changes are split into several smaller, compatible steps. Each step is zero-downtime and without breaking changes. This approach is preferred according to Evolution of Messages.
For the step-by-step procedure, see How to: apply EMC Message Evolution to a Kafka message type.
Strategy: EMC Message Replacement
Whenever possible, the EMC Message Evolution strategy should be preferred! See Evolution of Messages
| Recommendation | Description | Reason |
|---|---|---|
| New message | With this strategy, an independent, new message is defined - not a new message version of the old message. It's recommended to name the new message <oldMessageName>V2<postfix>. Example: JmeDeclarationCreatedV2Event, JmeCreateDeclarationV2Command. If the new message consists of further Avro records, it's also recommended to add the version to the namespace as well (e.g. @namespace("ch.admin.bit.jme.declaration.v2")). This makes the record definition self-contained, so the new version doesn't need to reference objects of a previous version. | Completely independent of the old message: no restrictions from Avro compatibility rules, no conflicts in the Java code |
| New topic | The new message should be published on a new topic. From the naming convention this follows: <system>-<context>-declarationcreated-v2, <system>-<context>-createdeclaration-v2 | Unchanged subscribers wouldn't be able to process the new messages on the topic |
| Same idempotence ID | The idempotence ID of the corresponding new and old message must be identical | Until the subscriber migrates to the new message/topic, the publisher has already published messages to the new topic. As soon as the subscriber migrates to the new message/topic, it will receive some messages that it has already processed as "old" messages |
| Start with earliest | The subscriber should read all messages from the new topic. See Kafka consumer configs: auto.offset.reset | If the subscriber were to start with the default "latest", there would be a risk that it misses some messages |