Query caching

    Segment-level caching allows the cache to be leveraged even when some of the underling segments are mutable and undergoing real-time ingestion. In this case, Druid will potentially cache query results for immutable historical segments, while re-computing results for the real-time segments on each query. Whole-query result level caching is not useful in this scenario, since it would be continuously invalidated.

    Segment-level caching does require Druid to merge the per-segment results on each query, even when they are served from the cache. For this reason, whole-query result level caching can be more efficient if invalidation due to real-time ingestion is not an issue.

    Brokers support both segment-level and whole-query result level caching. Segment-level caching is controlled by the parameters and populateCache. Whole-query result level caching is controlled by the parameters useResultLevelCache and populateResultLevelCache and runtime properties druid.broker.cache.*.

    Enabling segment-level caching on the Broker can yield faster results than if query caches were enabled on Historicals for small clusters. This is the recommended setup for smaller production clusters (< 5 servers). Populating segment-level caches on the Broker is not recommended for large production clusters, since when the property is set to true (and query context parameter populateCache is not set to false), results from Historicals are returned on a per segment basis, and Historicals will not be able to do any local result merging. This impairs the ability of the Druid cluster to scale well.

    Larger production clusters should enable segment-level cache population on Historicals only (not on Brokers) to avoid having to use Brokers to merge all query results. Enabling cache population on the Historicals instead of the Brokers enables the Historicals to do their own local result merging and puts less strain on the Brokers.

    Task executor processes such as the Peon or the experimental Indexer only support segment-level caching. Segment-level caching is controlled by the query context parameters useCache and populateCache and druid.realtime.cache.*.

    Note that the task executor processes only support caches that keep their data locally, such as the cache. This restriction exists because the cache stores results at the level of intermediate partial segments generated by the ingestion tasks. These intermediate partial segments will not necessarily be identical across task replicas, so remote cache types such as memcached will be ignored by task executor processes.