{
  "slug": "front-coding",
  "term": "Front coding",
  "aliases": [
    "Front-coding",
    "Key-prefix compression"
  ],
  "definition": "Front coding represents a string using its common-prefix length with a preceding string and the remaining suffix.",
  "note": "Dictionary: Lexicographically sorted strings often share prefixes. Bucketed front coding stores each bucket's first string explicitly, then encodes following strings relative to their predecessors. Search can binary-search bucket headers and reconstruct the selected bucket sequentially. [dictionary]\n\nBytes: LevelDB 1.23 counts shared and unshared key bytes, not Unicode characters. A common byte prefix can end inside a UTF-8 code point; reconstruct the complete bytes before interpreting text. [builder]\n\nStorage: Full-key restart entries limit reconstruction dependencies. Entry length fields and restart offsets also consume space, so suffix-byte savings alone do not establish total block savings. Optional whole-block compression is a separate later step. [builder] [writer]\n\nScope: Prefix coding is a reversible representation, not a prefix Bloom membership test. Restart spacing trades metadata and repeated key bytes against reconstruction work; it does not predict hardware latency. [reader]",
  "related": [
    "sstable-restart-point",
    "lossless-compression"
  ],
  "citations": [
    {
      "id": "dictionary",
      "title": "Brisaboa et al. (2011): Compressed String Dictionaries, section 2.4",
      "url": "https://arxiv.org/pdf/1101.5506v1",
      "accessed": "2026-11-17"
    },
    {
      "id": "builder",
      "title": "LevelDB 1.23: BlockBuilder key-prefix encoding and restart offsets",
      "url": "https://github.com/google/leveldb/blob/99b3c03b3284f5886f9ef9a4ef703d57373e61be/table/block_builder.cc",
      "accessed": "2026-11-17"
    },
    {
      "id": "writer",
      "title": "LevelDB 1.23: TableBuilder::WriteBlock and optional block compression",
      "url": "https://github.com/google/leveldb/blob/99b3c03b3284f5886f9ef9a4ef703d57373e61be/table/table_builder.cc",
      "accessed": "2026-11-17"
    },
    {
      "id": "reader",
      "title": "LevelDB 1.23: Block::Iter seek and reconstruction",
      "url": "https://github.com/google/leveldb/blob/99b3c03b3284f5886f9ef9a4ef703d57373e61be/table/block.cc",
      "accessed": "2026-11-17"
    },
    {
      "id": "hesela",
      "title": "Hesela: Front coding needs a complete byte ledger",
      "url": "https://hesela.com/analyses/bloom-filters-lsm-read-cost/#front-coding-ledger",
      "accessed": "2026-11-17"
    }
  ],
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-17",
  "provenance": [
    "Primary-source synthesis, with UTF-8 implications derived from byte-prefix semantics. Native LevelDB 1.23 block-builder and reader checks match 658 constructed raw-key, empty-value cases, including the accompanying byte ledger; this is not a database compression or performance benchmark."
  ]
}
