Notes

Part 11 of 11

Looking back

The choice of encoding affects more than speed. It shapes your architecture and how easily you can change your app.

Rolling upgrades are a big win for evolvability:

  • You release new versions without downtime.
  • That encourages frequent, small releases instead of rare, big ones.
  • Deploys get less risky, because you spot a bad release early and roll it back before it hurts many users.

To make them work, assume different machines run different versions of your code, and make all data both backward and forward compatible.

Kind of formatStrengthsWeaknesses
Language-specificEasy to useOne language only, weak compatibility, security risk
Text (JSON, XML, CSV)Used everywhereCompatibility depends on how you use them; schemas optional; vague about numbers and binary data
Binary with schema (protobuf, Avro)Compact, clear compatibility rules, schemas as docs, generated codeNot readable by people until decoded
Dataflow modeWho encodesWho decodes
DatabaseThe writerThe reader
REST or RPCThe client encodes the request; the server encodes the responseThe server decodes the request; the client decodes the response
Events and messagesThe senderThe receiver

Key takeaways

  • Old and new code and data always overlap, so plan for backward compatibility (new reads old) and forward compatibility (old reads new).
  • Old code must keep fields it does not understand, or a read-change-write cycle loses data.
  • Built-in language serializers are for short-lived data only; JSON, XML, and CSV are everywhere but vague about numbers and binary data.
  • Protobuf replaces field names with tags: never change or reuse a tag, and add new fields with new tags.
  • Avro stores bare values, needs the writer's schema, and only adds or removes fields that have defaults.
  • Schemas give compact data, documentation that stays true, compatibility checks, and type-checked code.
  • Data outlives code, so databases mix many schema versions and migrate lazily.
  • A network call is not a local call: plan for lost replies, timeouts, retries, and idempotence, whether you use RPC, workflows, or message brokers.

Go deeper: DDIA, 2nd edition, chapter 5: Encoding and Evolution

Based on the ideas in Designing Data-Intensive Applications, 2nd edition, by Martin Kleppmann and Chris Riccomini (O'Reilly). Written in our own words; Recurse is not part of the book or its publisher. Get the book