Changing Config and Shape Safely
Lesson 3 of 4
Change a Shape in Two Deployments
Estimated time: 10 minutes
A shape shared between an agent and its callers cannot move in a single step. The moment the writer uses the new form, the readers that have not moved are reading something they do not understand, and the failure shows up far from the change.
Expand and contract puts a period between the two halves. First the shape is expanded so both the old and the new form are accepted and written. Records already stored are backfilled into the new form. Readers are moved across. Only when no reader wants the old form is it contracted away.
def read(record, form):
if form == 'new':
return record.get('new', record['old'])
return record['old'] # old form stays readable until every reader moves
The trap is contracting too early. A single reader still asking for the old form is enough to break it, so the switch is confirmed before the removal, not assumed.