Skip to content

Overview

State synchronization over a network involves repeatedly transmitting the same shape of state with small changes between frames. To optimize bandwidth, it's important to have an efficient encoding scheme for the wire format.

Delta-Pack achieves ultra-compact encodings by combining two core concepts:

  • Schema-driven binary encoding, like Protobuf. Both client and server have a shared schema. They already know the field names, types, and structure, allowing the wire format to carry only values.
  • Structural delta encoding, like JSON Patch. Only changed data is serialized, with as few bits as possible.

The result is wire sizes that are smaller than Protobuf for snapshots, and oders of magnitude smaller than JSON Patch for diffs — see Benchmarks.

Example

Define your data schema using the supported data types, either programmatically with language-native APIs or with YAML:

yaml
# schema.yml
Team:
  - RED
  - BLUE
  - GREEN

Position:
  x: float(precision=0.1)
  y: float(precision=0.1)

Player:
  name: string
  position: Position
  health: uint
  team: Team?

Given two snapshots of a Player, where position and health have changed:

jsonc
// state1.json — 71 bytes as compact JSON
{"name":"Alice","position":{"x":1.0,"y":3.5},"health":100,"team":"RED"}

// state2.json — x moved, health dropped
{"name":"Alice","position":{"x":2.3,"y":3.5},"health":82,"team":"RED"}

Delta-Pack compactly encodes snapshot and diff forms:

bash
$ delta-pack encode schema.yml --type Player --input state1.json
# → 11 bytes (snapshot)

$ delta-pack encode-diff schema.yml --type Player --old state1.json --new state2.json
# → 5 bytes (diff)

Released under the MIT License.