All posts

Dynamic Shredding: Resolving the Conflict Between Schemaless Ingestion and Columnar Query Speed

graphical user interface
Photo by Deng Xiang (https://unsplash.com/@dengxiangs) on Unsplash (https://unsplash.com/photos/graphical-user-interface--WXQm_NTK0U)

Observability pipelines and analytical log engines have long operated under a structural compromise. Producing applications favor schemaless JSON payloads because they decouple application releases from database migrations, allowing developers to introduce or alter nested metadata fields arbitrarily. Analytical engines, by contrast, require strongly typed columnar data to execute fast filter, aggregation, and projection operations across billions of records.

When unstructured or semi-structured JSON is stored verbatim as raw text or binary blobs (such as JSONB), the analytical engine must deserialize payload bytes at query time. This introduces significant CPU overhead and forces full row scans, negating the primary advantages of columnar storage: column projection pushdown, dictionary compression, and vectorized execution.

Dynamic shredding at write time bridges this divide. As detailed by Pydantic and analyzed in the accompanying community discussion on Hacker News, dynamically decomposing nested JSON documents into typed physical columns at the ingestion boundary allows engines to retain schema flexibility without sacrificing analytical throughput.

The Mechanics of Write-Time Shredding

Dynamic shredding processes nested objects as an ingestion micro-batch rather than treating the incoming record as an opaque payload. When an event arrives:

  1. Path Flattening and Type Inference: The ingest worker inspects nested keys (for example, context.user.id or metrics.latency_ms) and infers the scalar primitive types (such as Int64, Float64, Utf8, or Boolean).
  2. Columnar Projection: The leaf nodes of the nested hierarchy are extracted into separate, typed column vectors (unverified: the exact internal intermediate representation used by Pydantic’s pipeline).
  3. Schema Evolution: If a newly observed key has not been seen in the current storage block, the storage engine registers the new column dynamically, populating historical rows within that block with null values.
  4. Collision Handling: If a key appears with conflicting data types across different payloads (such as user_id arriving as an integer in one service and a string in another), the shredding engine must either promote the column to a union type, coerce compatible values, or route the conflicting field to a fallback semi-structured overflow column (unverified: the specific collision resolution algorithm implemented in the 2026-01-26 release).

By converting key paths into discrete physical columns within columnar formats like Apache Parquet or Arrow-native table engines, queries targeting specific nested attributes can skip non-matching columns entirely.

Eliminating the Query Penalty

The performance gap between raw JSON scans and shredded columnar queries is substantial. In traditional log platforms, scanning a query such as:

SELECT avg(payload.duration_ms) 
FROM logs 
WHERE payload.service = 'checkout'
  AND payload.environment = 'production';

requires reading the entire payload field off disk or memory, parsing the JSON byte stream, and evaluating keys for every single record.

With dynamic shredding, the storage engine exposes payload.duration_ms, payload.service, and payload.environment as native physical columns. The query engine reads only the storage blocks containing those three fields. Non-relevant metadata (such as large stack traces, request headers, or downstream trace contexts) remains unread on disk.

Furthermore, columnar compression algorithms like run-length encoding (RLE), frame-of-reference (FoR), and dictionary encoding operate with high efficiency on isolated scalar vectors. Low-cardinality fields like payload.environment compress to fractions of a bit per row, and min/max zone maps allow analytical engines to skip whole data pages during the initial file prune phase.

Engineering Constraints and Architectural Tradeoffs

While dynamic shredding resolves the query-speed bottleneck, it shifts operational complexity to the ingestion pipeline. Platform architects evaluate several tradeoffs when adopting this architecture, as highlighted in the Hacker News discussion:

Architectural Takeaway

Dynamic shredding shifts the computational burden of semi-structured data from query time to write time. By performing structural normalization and scalar typing during ingestion, systems provide backend engineers with the operational convenience of unstructured logging while maintaining the query latency and cost economics expected of modern analytical platforms. For data platform leads handling large log volumes, write-time dynamic shredding eliminates the need to enforce strict client-side schemas just to protect downstream query performance.