Communication & Data Transfer/JSON:API & Contract-First Design

Contract-First & Schema Evolution

Avro/Protobuf/JSON Schema at boundaries, compatibility modes, consumer-driven contracts, and avoiding breaking changes in polyglot fleets.

3/5Overview: 35m

Serialization formats at boundaries

FormatSchemaHuman-readableTypical use
JSONOptional (JSON Schema)YesPublic REST, config
XMLXSD/DTDVerboseLegacy enterprise, SOAP
Protocol Buffers.proto requiredNo (binary)gRPC, internal RPC
Avro.avsc with registryNoKafka, data pipelines
MessagePack/CBORInformalNoCompact JSON-like

Topic 5 goes deep on protobuf/gRPC. Here: evolution rules apply to all.

Compatibility modes (Confluent/Protobuf registry)

  • Backward — new schema reads old data (add field with default)
  • Forward — old schema reads new data (add optional field only)
  • Full — both directions
  • Breaking — rename/remove without alias → new subject version or topic

Rules of thumb:

  • Add optional fields — usually safe
  • Remove fields — breaking unless consumers ignore unknowns
  • Change type — almost always breaking
  • Enum — never reuse numeric values

Consumer-driven contracts (Pact)

Consumer defines expected request/response; provider verifies in CI. Catches breaking changes before deploy — critical when 30 teams consume your API.

Flow: consumer test generates pact file → published to broker → provider verification job fails if response shape drifts.

Contract-first workflow

  1. Design OpenAPI / .proto / AsyncAPI in PR
  2. Review with consumers
  3. Generate stubs
  4. Implement + contract tests
  5. Deploy with compatibility checks in CI

Versioning serialized messages

For async (Kafka): new topic orders-v2 or schema registry version with compatibility check.

For sync (REST): URL/header version + additive JSON fields.

Dual-write / dual-read migration window when breaking change unavoidable — staff-level migration pattern.

JSON Schema at HTTP boundaries

Validate request bodies at gateway or service edge. OpenAPI 3 embeds JSON Schema. Catches bugs early; watch validation latency on hot paths.

Cross-reference: Data Engineering for Avro in Kafka pipelines; Databases → Object Storage for how Parquet is stored — this topic owns the HTTP/API contract and consumer-driven tests at team boundaries.

Further Reading

Hands-On Tasks (Optional)

API design drills and whiteboard exercises — protocol selection, contract design, and bulk-transfer architecture. Assumes Networking and sibling tracks on the hub page (Distributed Systems, Databases, Concurrency, LLD).

  • Classify schema changes

    For each change — add optional field, rename field, change int to string, remove enum value — label backward/forward compatible and pick mitigation (new field, version bump, dual-write).

    20m