|\n| value | number | Yes | Measured value | Any valid IEEE 754 double |\n| unit | enum | Yes | Unit of measurement | One of: celsius, fahrenheit, kelvin, percent, ppm |\n| timestamp | string | Yes | Reading time | ISO 8601 with timezone |\n| metadata | object | No | Key-value pairs | String keys and values |\n\n## Changelog\n| Version | Date | Changes |\n|---------|------|---------|\n| v1 | 2025-03-01 | Initial schema |\n\n## Compatibility\n- **Backwards**: Consumers of v1 will continue to work with future versions\n- **Policy**: Only additive, optional field changes between minor versions\n```\n\n**Got:** Docs auto-generated or stay in sync with schema definition.\n\n**If fail:** Docs drift from schema? Add CI check validating docs against schema source.\n\n## Checks\n\n- [ ] Schema uses right system (JSON Schema, Protobuf, Avro)\n- [ ] All fields have types, descriptions, constraints\n- [ ] Required vs optional fields explicit\n- [ ] Evolution strategy documented (safe changes, versioning policy)\n- [ ] Validation at system boundaries\n- [ ] Schema versioned with changelog\n- [ ] Round-trip test: serialize → deserialize → compare, no data loss\n\n## Pitfalls\n\n- **Over-constraining too early**: Strict validation on new schema blocks iteration. Start permissive (`additionalProperties: true`), tighten later.\n- **No default values**: New required field without default breaks existing data. Always provide defaults for new fields.\n- **Ignoring null**: Many schemas don't handle null/missing cleanly. Be explicit: nullable vs optional.\n- **Version in payload, not URL**: Long-lived data (storage, events) → embed schema version in data itself, not just endpoint URL.\n- **Enum exhaustiveness**: New enum value can crash consumers using exhaustive switch. Document: unknown values handled gracefully.\n\n## See Also\n\n- `serialize-data-formats` — format selection + encoding/decoding\n- `implement-pharma-serialisation` — pharma serialisation (regulatory schemas)\n- `write-validation-documentation` — validation docs for regulated schemas\n","licenseDocuments":[]}}
La interfaz está localizada; las descripciones y documentos de las Skills se traducen automáticamente con IA a su idioma. El código, los comandos, rutas y términos técnicos se mantienen en el original, y prevalece el documento del autor.
Design serialization schemas using JSON Schema, Protocol Buffer definitions, or Apache Avro. Covers schema versioning, backwards compatibility, validation rules, and evolution strategies for long-lived data formats. Use when defining a new API contract or data interchange format, adding fields to an existing schema without breaking consumers, migrating betw…
Independent GitHub snapshot · Automated classification · Original documentation governs
name: design-serialization-schema
locale: caveman
source_locale: en
source_commit: 82c77053
fence_basis_commit: 82c77053
translator: "Julius Brussee homage — caveman"
translation_date: "2026-04-24"
description: >
Design serialization schemas using JSON Schema, Protocol Buffer definitions,
or Apache Avro. Covers schema versioning, backwards compatibility, validation
rules, and evolution strategies for long-lived data formats. Use when defining
a new API contract or data interchange format, adding fields to an existing
schema without breaking consumers, migrating between schema versions, choosing
between schema systems, or documenting data validation rules for automated
enforcement.
license: MIT
allowed-tools: Read Write Edit Bash Grep Glob
metadata:
author: Philipp Thoss
version: "1.0"
domain: data-serialization
complexity: intermediate
language: multi
tags: json-schema, protobuf, avro, schema-evolution, versioning, compatibility
Design Serialization Schema
Make versioned serialization schemas. Evolve gracefully without breaking consumers.
When Use
Define new API contract or data interchange format
Add fields to existing schema without breaking consumers
Migrate between schema versions
Pick between schema systems (JSON Schema, Protobuf, Avro)
Document data validation rules for auto-enforcement
Inputs
Required: Data model (entity relations, field types, constraints)
Required: Compat needs (who consumes, how long must old formats read)
Got: Evolution plan documented. Safe changes vs new versions clear.
If fail: Breaking change unavoidable? Version schema (v1 → v2), keep parallel support during migration.
Step 4: Impl Schema Validation
# JSON Schema validation (Python)
from jsonschema import validate, ValidationError
import json
schema = json.load(open("measurement_v1.json"))
def validate_measurement(data: dict) -> list[str]:
"""Validate a measurement against the schema. Returns list of errors."""
errors = []
try:
validate(instance=data, schema=schema)
except ValidationError as e:
errors.append(f"{e.json_path}: {e.message}")
return errors
# Usage
errors = validate_measurement({"sensor_id": "s-01", "value": "not_a_number"})
# → ["$.value: 'not_a_number' is not of type 'number'"]
// TypeScript with Zod (runtime + compile-time)
import { z } from 'zod';
const MeasurementSchema = z.object({
sensor_id: z.string().regex(/^[a-z]+-[0-9]+$/),
value: z.number(),
unit: z.enum(['celsius', 'fahrenheit', 'kelvin', 'percent', 'ppm']),
timestamp: z.string().datetime(),
metadata: z.record(z.string()).optional(),
});
type Measurement = z.infer<typeof MeasurementSchema>;
// Validation
const result = MeasurementSchema.safeParse(inputData);
if (!result.success) {
console.error(result.error.issues);
}
Got: Validation runs on all incoming data at system boundaries (API endpoints, file ingestion).
If fail: Log validation errors with full payload (redact sensitive fields) for debugging.
Step 5: Document Schema
Make schema doc page:
# Measurement Schema (v1)
## Overview
Represents a single sensor reading with metadata.
## Fields
| Field | Type | Required | Description | Constraints |
|-------|------|----------|-------------|-------------|
| sensor_id | string | Yes | Unique sensor ID | Pattern: `^[a-z]+-[0-9]+
design-serialization-schema · Skills-SI Market
|
| value | number | Yes | Measured value | Any valid IEEE 754 double |
| unit | enum | Yes | Unit of measurement | One of: celsius, fahrenheit, kelvin, percent, ppm |
| timestamp | string | Yes | Reading time | ISO 8601 with timezone |
| metadata | object | No | Key-value pairs | String keys and values |
## Changelog
| Version | Date | Changes |
|---------|------|---------|
| v1 | 2025-03-01 | Initial schema |
## Compatibility
- **Backwards**: Consumers of v1 will continue to work with future versions
- **Policy**: Only additive, optional field changes between minor versions
Got: Docs auto-generated or stay in sync with schema definition.
If fail: Docs drift from schema? Add CI check validating docs against schema source.
Checks
Schema uses right system (JSON Schema, Protobuf, Avro)