You Didn't Ship a Bug. You Just Wrote It for a Human. - Ravi Madabhushi, Scalekit
This video details the creation of a real-time, high-throughput analytics system using Apache Flink and Apache Pinot, designed to handle large-scale event processing and low-latency queries. The architecture leverages Flink for stream processing, enrichment, and deduplication, feeding data into Pinot for real-time aggregation and ad-hoc analytics. Key takeaways include the importance of a robust streaming layer for data integrity and the power of columnar stores like Pinot for interactive, OLAP-style queries on fresh data.
read more
The core of this system addresses the challenge of building a real-time analytics pipeline capable of handling millions of events per second with sub-second query latency. The architecture centers around Apache Flink for stream processing and Apache Pinot for real-time analytical queries.
Data ingress begins with events arriving in Apache Kafka, serving as the durable, scalable message bus. From Kafka, events are consumed by Flink. The Flink application is designed to perform several critical operations. Initially, it handles data deserialization and basic validation. A key component is data enrichment, where incoming events are augmented with additional context from external sources (e.g., user profiles, geo-location data). This enrichment is often done by joining the event stream with data from a changelog stream or a lookup table in a fast key-value store.
Deduplication is another crucial Flink task, ensuring data integrity, especially in 'at-least-once' processing environments. Flink's stateful processing capabilities are leveraged here, often using a combination of event time and processing time windows along with state backends (like RocksDB) to track seen events based on a unique identifier. This ensures that each unique event is processed exactly once before being committed downstream.
After processing, Flink pushes the refined and enriched data into Apache Pinot. Pinot is chosen for its columnar storage format and segment-based architecture, which are ideal for low-latency analytical queries. Data is ingested into Pinot in real-time through its Kafka connector. Pinot organizes data into time-based segments, which can be stored in distributed file systems or object stores. As new data arrives, new segments are created, and old segments are merged or optimized.
Pinot's query engine is highly optimized for OLAP-style queries, supporting a wide range of aggregations, filters, and group-by operations. Its inverted indices, star-tree indices, and bloom filters significantly accelerate query performance. For instance, filtering on high-cardinality dimensions or performing complex aggregations over large datasets can be executed in milliseconds. The system specifically highlights Pinot's ability to handle upserts and updates on records, which is crucial for managing evolving user data or correcting past events, although this often requires careful consideration of segment boundaries and indexing strategies.
Deployment strategies are also discussed, emphasizing the use of containerization (Docker, Kubernetes) for both Flink and Pinot components. Flink jobs are typically deployed as long-running applications on a Kubernetes cluster, leveraging Flink's checkpointing and savepointing features for fault tolerance and state recovery. Pinot clusters consist of multiple components: Controller (for metadata management), Broker (for query routing), Server (for data storage and query execution), and Minion (for offline segment processing). Scaling is achieved horizontally by adding more Flink task managers and Pinot servers/brokers.
Concrete examples include tracking user behavior on a website, where events like 'page view', 'click', and 'add to cart' are processed. Flink enriches these events with user demographics, and Pinot then allows for real-time dashboards showing active users, conversion rates, and funnel analysis. The system aims to provide a unified platform for both real-time operational analytics and historical data exploration.