K-Pg: Shared State in Differential Dataflows

Frank McSherry, Andrea Lattuada, Malte Schwarzkopf

Abstract

Current systems for data-parallel, incremental processing and view maintenance over high-rate streams isolate the execution of independent queries. This creates unwanted redundancy and overhead in the presence of concurrent incrementally maintained queries: each query must independently maintain the same indexed state over the same input streams, and new queries must build this state from scratch before they can begin to emit their first results. This paper introduces shared arrangements: indexed views of maintained state that allow concurrent queries to reuse the same in-memory state without compromising data-parallel performance and scaling. We implement shared arrangements in a modern stream processor and show order-of-magnitude improvements in query response time and resource consumption for interactive queries against high-throughput streams, while also significantly improving performance in other domains including business analytics, graph processing, and program analysis.

Problem Statement

Modern stream processing systems, such as Apache Flink or Spark Streaming, excel at incrementally maintaining query results. However, these systems typically isolate queries, treating each as an independent unit. This isolation leads to three major inefficiencies when multiple queries operate on the same data streams:

  1. Redundant Computation: CPU cycles are wasted updating identical indices for different queries.
  2. Memory Bloat: RAM is consumed by redundant copies of the same data.
  3. High Cold Start Latency: New queries must scan the entire history of an input stream to build private state, causing delays that are unacceptable for interactive use cases.

Methodology: Shared Arrangements

The authors propose shared arrangements within the Differential Dataflow (DD) framework to decouple index maintenance from its consumption. The architecture centers on three components:

  • The Trace: A multiversioned, sharded, append-only data structure using a Log-Structured Merge (LSM) tree approach to store update batches.
  • The Arrange Operator: A single-writer component that partitions incoming updates and writes them to the Trace.
  • Read Handles: Multiple reader components (e.g., Join or Group operators) that attach to an existing Trace to access state.
Architecture of shared arrangements in Differential Dataflow.

The system utilizes logical multiversioning, allowing different queries to view the state at specific logical times. This enables concurrent readers to operate at different speeds without interference, as they can "see" the state as it existed at any point in the past that hasn't been compacted away.

Evaluation

The implementation was evaluated across several diverse workloads, including a streaming variant of TPC-H (Scale Factor 10), interactive graph queries on a 10M-node graph, and recursive Datalog workloads. The system was also tested on large-scale program analysis tasks (Graspan) and a massive Twitter graph with 1.4B edges.

Key Results

Shared arrangements demonstrate significant performance gains across all metrics:

  • Query Installation Latency: Reduced from seconds to milliseconds in TPC-H workloads—an order-of-magnitude improvement that enables truly interactive streaming queries.
  • Memory Efficiency: Footprint reduced by 2–4x; memory usage remains relatively flat as query count increases rather than growing linearly.
  • Update Latency: Processing speeds improved by 1.3–3x due to the elimination of redundant index maintenance.
Performance comparison of shared vs. non-shared arrangements.

Discussion and Future Work

The "single-writer, multiple-reader" model proves to be a sweet spot for dataflow systems, avoiding the locking overhead common in relational databases. By sharing the physical representation (the index) rather than just computation, the system achieves instant query deployment.

However, limitations remain. Sharing requires exact key matching, and the single-writer constraint limits flexibility. Furthermore, shared state "entangles" queries, meaning a failure in one can affect others sharing the same worker state. Future work may involve persisting Trace layers to distributed storage to enable serverless streaming queries with instant startup from shared persistent indices.

Summary updated

BibTeX
@article{mcsherry2020k,
  author = {Frank McSherry and Andrea Lattuada and Malte Schwarzkopf},
  title = {{K-Pg: Shared State in Differential Dataflows}},
  journal = {Proc. VLDB Endow.},
  year = {2020},
  doi = {10.14778/3401960.3401974},
}
Figure