Skip to main content

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!

Procedure for EMC with a new, incompatible major version​

The procedure is always the same:

StepDescription
EXPANDThe provider offers a new interface
MIGRATEThe consumers (1..N) migrate to the new interface
CONTRACTThe 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​

Expand - Migrate - Contract for a REST API

Command​

Expand - Migrate - Contract for a Command

  1. Not Avro-compatible:
    • New major version of the Command
      • New name of the Avro schema
      • New names of the Java classes

Event​

Expand - Migrate - Contract for an Event

  1. Not Avro-compatible:
    • New major version of the Event
      • New name of the Avro schema
      • New names of the Java classes

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

RecommendationDescriptionReason
New messageWith 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 topicThe new message should be published on a new topic. From the naming convention this follows: <system>-<context>-declarationcreated-v2, <system>-<context>-createdeclaration-v2Unchanged subscribers wouldn't be able to process the new messages on the topic
Same idempotence IDThe idempotence ID of the corresponding new and old message must be identicalUntil 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 earliestThe subscriber should read all messages from the new topic. See Kafka consumer configs: auto.offset.resetIf the subscriber were to start with the default "latest", there would be a risk that it misses some messages