Skip to main content

Sub-second queries
over events that just arrived.

Druid answers analytical, slice-and-dice queries over large volumes of events, and data is available for querying as soon as it arrives. It partitions data by time, stores each part in a columnar, indexed format, and processes each query in parallel across the cluster. Follow an event from arrival to query and see what happens when a server goes down.

Apache Druid is a real-time analytics database built for OLAP queries over large volumes of event-oriented data. Data is kept in datasources, partitioned by time and stored in columnar segments, served in parallel by the servers in the cluster.

Real time

Queryable as soon as it arrives

An event read from a stream, such as a Kafka topic, already answers queries before it moves to permanent storage. Batch loading follows the same path.

By time

Only the requested interval

Data is partitioned first by time, and a query reads only the parts that fall within the interval it asks for.

In parallel

One query, many servers

The Broker splits each query among the servers that hold the segments, and each one reads only the rows and columns the query needs.

On this page

Watch an event reach a query​

Press Play or step through. Underlined names lead to the Glossary.

KafkaWhere the events come from
TopicPartitions and offsets
Master serverControls ingestion and data
OverlordSupervisor and tasks
CoordinatorAssigns the segments
Data serversIngest and serve the data
MiddleManagerReceives the tasks
PeonRuns a task
HistoricalServes the published segments
External dependenciesWhere segments and metadata are kept
Deep storageCopy of all segments
Metadata storeSegment records
Step 1 of 7

1 The supervisor creates the tasks

A Kafka ingestion is controlled by a supervisor that runs on the Overlord. It creates the indexing tasks that read the topic and tracks their state throughout the ingestion.

  1. The supervisor creates the tasks. A Kafka ingestion is controlled by a supervisor that runs on the Overlord. It creates the indexing tasks that read the topic and tracks their state throughout the ingestion.
  2. Each task gets a Peon. The Overlord hands the tasks to the MiddleManagers. Each MiddleManager runs each task in its own Peon, a separate JVM, which isolates the task's resources and logs.
  3. The Peon reads the topic. The Peon reads events through Kafka partitions and offsets. Before building a segment, it asks the Overlord for the segment's identifier.
  4. The event already answers queries. As soon as it enters the segment being built, the event is already queryable: the segment is available, but not yet published. Meanwhile, the data is converted to the columnar format, indexed with bitmaps, and compressed.
  5. The segment is published. Once the segment is fully read, the Peon pushes it to deep storage and publishes it with a record in the metadata store. The Kafka offsets are committed in the same transaction as the segment metadata.
  6. The Coordinator finds the new segment. The Coordinator polls the metadata store periodically. When it finds a published segment that nobody serves, it picks a Historical and tells it to load the segment.
  7. The Historical takes over the segment. The Historical downloads the segment from deep storage to the segment cache, announces that it serves it, and starts answering for it. This is the handoff: the task, which was waiting for this moment, exits.
Figure 1 - Streaming ingestion in Druid. A Peon reads Kafka and builds a segment that is already queryable. The segment goes to deep storage, is published to the metadata store, and is then served by a Historical.

Architecture​

Master servers govern, Query servers receive the queries, Data servers ingest and serve. Three external dependencies complete the cluster.

Druid services are organized into three types of server.

Apache Druid architecture: Master, Data and Query servers and the external dependenciesThe Master server groups the Overlord, which assigns ingestion tasks to the MiddleManagers, and the Coordinator, which distributes segments among the Historicals and monitors the metadata storage. The Data server groups the MiddleManager, whose Peons read the streaming and batch sources and send the segments to deep storage, and the Historical, which loads segments from deep storage into its cache and serves them. The Query server groups the Router, the entry point for clients, and the Broker, which sends subqueries to the Historicals and the Peons and merges the results. ZooKeeper handles service discovery and leader election.Data sourcesStreaming: Kafka topicsBatch: files and SQLClientsAnalytics applications and APIsMaster serverOverlordAssigns ingestion tasksSupervisorsCoordinatorDistributes and balances segmentsacross the HistoricalsData serverMiddleManagerReceives tasksPeonPeonHistoricalServes published segmentsSegment cacheQuery serverRouterSingle entry pointand web consoleBrokerDistributes subqueriesand merges resultsMetadata storageRecord of segments and tasksDeep storageA copy of all segmentsZooKeeperService discovery and leader electionIngestionTasks and segmentsSegments in deep storagePublished segmentsQueriesDiscovery
Figure 2 - Druid architecture: Master, Data, and Query servers, with deep storage, the metadata store, and ZooKeeper. Underlined terms lead to the Glossary.

What the figure shows:

  1. The data sources are, in streaming, the Kafka topics and, in batch, files and SQL. The Peons read the streaming and batch sources.
  2. The clients are analytical applications and APIs. The Router is their entry point.
  3. The Master server brings together the Overlord and the Coordinator. The Overlord controls ingestion and distributes the ingestion tasks to the MiddleManagers. The supervisors run on it. The Coordinator manages data availability, distributes and balances the segments across the Historicals, and tracks the metadata store.
  4. The Data servers bring together the MiddleManager and the Historical. The MiddleManagers receive the tasks and run ingestion in their Peons, which send the segments to deep storage. The Historicals serve the data that is already published: they load the segments from deep storage into their segment cache and serve them.
  5. The Query server brings together the Router and the Broker. The Router is the single entry point and the web console. The Broker distributes the subqueries, sending them to the Historicals and the Peons, and combines the results.
  6. The metadata store sits outside Druid, with the records of the segments and the tasks.
  7. The deep storage sits outside Druid, with a copy of all segments.
  8. ZooKeeper sits outside Druid and handles service discovery and leader election.

Each service is configured and scaled independently, and the failure of one does not immediately affect the others.

Watch a query happen​

A query enters through the Router, is split by the Broker, and comes back already aggregated.

ClientApplication or dashboard
ClientSends SQL or a native query
Query serverReceives and splits the query
RouterEntry point
BrokerSplits and merges
Data serversRun the subqueries
HistoricalPublished segments
PeonSegments being built
ZooKeeperService discovery
ZooKeeperWhere services announce themselves
Step 1 of 6

1 The Broker already knows who serves what

The Broker discovers the Historicals and the streaming-ingestion Peons through ZooKeeper and asks each one, over HTTP, which segments it serves. With that, it keeps, for each datasource, a timeline of the segments and of who serves them.

  1. The Broker already knows who serves what. The Broker discovers the Historicals and the streaming-ingestion Peons through ZooKeeper and asks each one, over HTTP, which segments it serves. With that, it keeps, for each datasource, a timeline of the segments and of who serves them.
  2. The query enters through the Router. The client sends the query, in Druid SQL or the native language, to the Router, which forwards it to a Broker. An SQL query is planned on the Broker itself.
  3. The Broker prunes by time. The Broker identifies the segments that may have data for the query. The list is always pruned by time interval and can also be pruned by other attributes, depending on the datasource's partitioning. Per-segment results already in the Broker's cache are reused.
  4. One subquery for each server. The Broker sends a rewritten version of the query to each Historical and each Peon that serves the selected segments. Published segments are on the Historicals. Data that has just arrived is on the Peons.
  5. Each segment reads only what is needed. Within each segment, the indexes point to the rows that match the filters before any data is read. Then, only the rows and columns the query uses are read.
  6. The Broker merges the partial results. The servers return partial results to the Broker, which merges them into the final response and returns it to the client.
Figure 3 - Query processing in Druid. The Broker prunes segments by time, sends a subquery to each server that serves them, and merges the partial results.

The name of a segment​

Every segment has a four-part identifier. In the example, a segment of the clarity-cloud0 datasource, with one hour of data.

Click each part of the identifier.

Datasource

The dataset the segment belongs to, equivalent to a table.

See in the Glossary
clarity-cloud0 — Datasource
The dataset the segment belongs to, equivalent to a table.
2018-05-21T16:00:00.000Z — Interval start
The start of the time chunk that contains the segment. The length of the interval is the segment granularity defined at ingestion.
2018-05-21T17:00:00.000Z — Interval end
The end of the same time chunk. Start and end together form the segment's time interval.
2018-05-21T15:56:09.909Z — Version
Generally, the moment the set of segments started. A higher version replaces the previous one in the same interval.
1 — Partition
The partition number, unique for the same datasource, interval, and version. The first partition of a time chunk, number zero, omits this part of the identifier.

Segments of the same datasource, interval, and version together form the data for that interval. When data in an interval is overwritten, the new set carries the same datasource and interval identification, with a higher version.

From datasource to column​

Druid data, from the broadest level to the most concrete: each level contains the next.

Level 1 of 4

Datasource

The dataset that is queried, like a table in a relational database, partitioned first by time.

  • Primary timestampThe mandatory time column, stored as __time, by which the data is partitioned and ordered.
  1. Datasource. The dataset that is queried, like a table in a relational database, partitioned first by time.
    • Primary timestamp. The mandatory time column, stored as __time, by which the data is partitioned and ordered.
  2. Time chunk. A time interval of the datasource, such as a day or an hour, depending on the granularity chosen at ingestion.
    • Segment version. Distinguishes the sets of segments in the same interval, so that an overwrite replaces the data all at once.
  3. Segment. A single file, columnar, indexed, and compressed, with up to a few million rows of the time chunk.
    • Rollup. The optional pre-aggregation at ingestion, which merges identical rows and reduces the stored volume.
  4. Column. The data of each column is kept in separate structures inside the segment, and the query reads only the columns it uses.
    • Dimension. The column stored as is, for grouping and filtering, with a dictionary, a list of values, and bitmaps.
    • Metric. The column stored in aggregated form, such as a sum or a count.
    • Bitmap index. One bitmap per dimension value, which marks the rows that contain that value.
Figure 4 - The levels of data in Druid. The terms beside each level go with that level.

When something changes or fails​

Published segments are immutable and always have a copy in deep storage. This is what makes it possible to replace data and servers without losing anything.

Overwritten data

An overwrite creates new segments for the same interval, with a higher version. Druid loads the new ones without exposing them, switches all new queries to them at once, and drops the old ones shortly after. See Segment version.

Streaming task fails

Data not yet published can be discarded, and ingestion resumes from the last offsets committed to the metadata store. Because offsets and segments are committed in the same transaction, each event is published exactly once.

A Historical goes down

The Coordinator notices that the service has gone missing, treats its segments as dropped, and reassigns them to other Historicals, which download them from deep storage. With replicas, queries remain possible during recovery.

A Historical comes back quickly

For a while, the Coordinator does not reassign the dropped segments. If the Historical comes back within that interval, it looks in its own segment cache, announces what it finds, and resumes serving, without moving anything in the cluster.

All data servers

Even if all data servers are lost and re-provisioned, Druid rebuilds itself from the deep storage.

Coordinator or Overlord

With more than one instance, the leader of each is elected by ZooKeeper, and the others stand by. The Router can forward management requests to the active Coordinator and Overlord.

Why Druid​

Columnar

Only the query's columns

Column-oriented storage loads only the columns the query needs, each one optimized for its data type. See Columnar model.

Real time or batch

Data ready on arrival

Ingestion can be real-time or batch, and ingested data is available for querying immediately.

Time partitioning

Queries that read less

Data is partitioned first by time, and optionally by other fields, and queries access only the partitions in the requested interval.

Indexes

Fast filters

Compressed bitmap indexes allow fast filtering and searching across several columns at once.

Self-balancing

Servers come and go

The cluster grows or shrinks as servers are added or removed and rebalances itself in the background, with no downtime. When a server fails, the data is served by others until it is replaced.

Aggregation

Rollup and approximate algorithms

Pre-aggregation at ingestion reduces the stored data, and approximate algorithms for distinct count, ranking, histograms, and quantiles answer with bounded memory. The exact versions remain available.

What it is for

Druid's architecture combines ideas from data warehouses, time series databases, and log search systems. It works best with event-oriented data and is often used as the database behind the interfaces of analytical applications and high-concurrency APIs that need fast aggregations.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter32.0.0TDP Datacenter components

In TDP Datacenter​

In TDP Datacenter, Druid is the DRUID service, installed and managed by Ambari.

Service components

DRUID_BROKER (master, one or more), DRUID_COORDINATOR (master, one or more), DRUID_HISTORICAL (slave, one or more), DRUID_MIDDLEMANAGER (slave, one or more), DRUID_OVERLORD (master, one or more) and DRUID_ROUTER (master, one or more). The DRUID_BROKER requires HDFS_CLIENT (HDFS). The DRUID_COORDINATOR requires HDFS_CLIENT (HDFS). The DRUID_HISTORICAL requires HDFS_CLIENT (HDFS). The DRUID_MIDDLEMANAGER requires HDFS_CLIENT (HDFS). The DRUID_OVERLORD requires HDFS_CLIENT (HDFS). The DRUID_ROUTER requires HDFS_CLIENT (HDFS). Component category.

Per-service configuration

Each Druid service has its own configuration in Ambari, from druid-coordinator to druid-router, and what applies to all of them is in druid-common.

Deep storage

The deep storage type is configurable in druid.storage.type, among local, S3, and HDFS, and the directory in druid.storage.storageDirectory.

Metadata store

The metadata store type, MySQL or PostgreSQL, is configurable in druid.metadata.storage.type, with the connection in druid.metadata.storage.connector.connectURI and the database name in database_name.

Coordination

The connection to the ZooKeeper ensemble is configurable in druid.zk.service.host, the base znode of Druid in druid.zk.paths.base, and the path under which services announce themselves in druid.discovery.curator.path.

Historical

The segment cache locations are configurable in druid.segmentCache.locations, the directory in which the Historical records the segments it serves in druid.segmentCache.infoDir, and the volume of segments each Historical accepts in druid.server.maxSize.

Query caches

Use of the results cache can be enabled on the Broker, in druid.broker.cache.useCache, and on the Historicals, in druid.historical.cache.useCache.

Coordinator and Overlord

The interval between Coordinator cycles is configurable in druid.coordinator.period, and the Coordinator can also take on the Overlord role, in druid.coordinator.asOverlord.enabled. On the Overlord, the task execution mode is configurable in druid.indexer.runner.type, and where their state is stored, in druid.indexer.storage.type.

MiddleManager

The maximum number of tasks per MiddleManager is configurable in druid.worker.capacity, the tasks' working directory in druid.indexer.task.baseTaskDir, and the resumption of tasks after a restart in druid.indexer.task.restoreTasksOnRestart.

Router

Forwarding of management requests to the active Coordinator and Overlord can be enabled in druid.router.managementProxy.enabled.

Memory

The memory of each service is configurable in druid-env, such as druid.broker.jvm.heap.memory and druid.historical.jvm.heap.memory.

Extensions

The extensions loaded by Druid are listed in druid.extensions.loadList.

Metrics and logs

The metrics destination, including Ambari Metrics, is configurable in druid.emitter, with the Ambari Metrics server in druid.emitter.ambari-metrics.hostname. The log directory is configurable in druid_log_dir, and rotation in druid-logrotate. See Observability in TDP Datacenter.

Security

The HTTPS connector can be enabled in druid.enableTlsPort. With Kerberos, the Druid principal and keytab are configurable in druid.hadoop.security.kerberos.principal and druid.hadoop.security.kerberos.keytab, and the security extensions in druid.security.extensions.loadList. See Security in TDP Datacenter.

Dependencies

Ambari requires in the cluster ZooKeeper and HDFS.

Who uses it

Trino queries Druid through the connector configurable in use.druid, OpenMetadata catalogs its metadata, Airflow integrates with it through the Druid provider, and NiFi, through the Druid components.

Next steps​

Sources​

Apache Druid Apache Druid - Introduction Apache Druid - Architecture Apache Druid - Storage overview Apache Druid - Segments Apache Druid - Deep storage Apache Druid - Query processing Apache Druid - Ingestion overview Apache Druid - Apache Kafka ingestion Apache Druid - ZooKeeper