Occasion Stream Analytics With Druid & Elasticsearch

Occasions are messages which might be despatched by a system to inform operators or different methods a couple of change in its area. With event-driven architectures powered by methods like Apache Kafka turning into extra distinguished, there at the moment are many functions within the fashionable software program stack that make use of occasions and messages to function successfully. On this weblog, we are going to look at using three completely different knowledge backends for occasion knowledge – Apache Druid, Elasticsearch and Rockset.

Utilizing Occasion Information

Occasions are generally utilized by methods within the following methods:

  1. For reacting to adjustments in different methods: e.g. when a cost is accomplished, ship the person a receipt.
  2. Recording adjustments that may then be used to recompute state as wanted: e.g. a transaction log.
  3. Supporting separation of knowledge entry (learn/write) mechanisms like CQRS.
  4. Assist understanding and analyze the present and previous state of a system.

We are going to give attention to using occasions to assist perceive, analyze and diagnose bottlenecks in functions and enterprise processes, utilizing Druid, Elasticsearch and Rockset along with a streaming platform like Kafka.

Kinds of Occasion Information

Functions emit occasions that correspond to vital actions or state adjustments of their context. Some examples of such occasions are:

  1. For an airline worth aggregator, occasions generated when a person books a flight, when the reservation is confirmed with the airline, when person cancels their reservation, when a refund is accomplished, and so forth.
// an instance occasion generated when a reservation is confirmed with an airline.
  "kind": "ReservationConfirmed",
  "reservationId": "RJ4M4P",
  "passengerSequenceNumber": "ABC123",
  "underName": {
    "title": "John Doe"
  "reservationFor": {
    "flightNumber": "UA999",
    "supplier": {
      "title": "Continental",
      "iataCode": "CO",
    "vendor": {
      "title": "United",
      "iataCode": "UA"
    "departureAirport": {
      "title": "San Francisco Airport",
      "iataCode": "SFO"
    "departureTime": "2019-10-04T20:15:00-08:00",
    "arrivalAirport": {
      "title": "John F. Kennedy Worldwide Airport",
      "iataCode": "JFK"
    "arrivalTime": "2019-10-05T06:30:00-05:00"
  1. For an e-commerce web site, occasions generated because the cargo goes via every stage from being dispatched from the distribution middle to being acquired by the customer.
// instance occasion when a cargo is dispatched.
  "kind": "ParcelDelivery",
  "deliveryAddress": {
    "kind": "PostalAddress",
    "title": "Pickup Nook",
    "streetAddress": "24 Ferry Bldg",
    "addressLocality": "San Francisco",
    "addressRegion": "CA",
    "addressCountry": "US",
    "postalCode": "94107"
  "expectedArrivalUntil": "2019-10-12T12:00:00-08:00",
  "service": {
    "kind": "Group",
    "title": "FedEx"
  "itemShipped": {
    "kind": "Product",
    "title": "Google Chromecast"
  "partOfOrder": {
    "kind": "Order",
    "orderNumber": "432525",
    "service provider": {
      "kind": "Group",
      "title": "Bob Dole"
  1. For an IoT platform, occasions generated when a tool registers, comes on-line, experiences wholesome, requires restore/alternative, and so forth.
// an instance occasion generated from an IoT edge gadget.
    "deviceId": "529d0ea0-e702-11e9-81b4-2a2ae2dbcce4",
    "timestamp": "2019-10-04T23:56:59+0000",
    "standing": "on-line",
    "acceleration": {
        "accelX": "0.522",
        "accelY": "-.005",
        "accelZ": "0.4322"
    "temp": 77.454,
    "potentiometer": 0.0144

These kinds of occasions can present visibility into a particular system or enterprise course of. They might help reply questions with regard to a particular entity (person, cargo, or gadget), in addition to help evaluation and analysis of potential points rapidly, in combination, over a particular time vary.

Constructing Occasion Analytics

Up to now, occasions like these would stream into an information lake and get ingested into an information warehouse and be handed off to a BI/knowledge science engineer to mine the info for patterns.

Earlier than




This has modified with a brand new technology of knowledge infrastructure as a result of responding to adjustments in these occasions rapidly and in a well timed method is turning into important to success. In a scenario the place each second of unavailability can rack up income losses, understanding patterns and mitigating points which might be adversely affecting system or course of well being have turn into time-critical workout routines.

When there’s a want for evaluation and analysis to be as real-time as attainable, the necessities of a system that helps carry out occasion analytics should be rethought. There are instruments focusing on performing occasion analytics in particular domains – similar to product analytics and clickstream analytics, however given the particular wants of a enterprise, we regularly need to construct customized tooling that’s particular to the enterprise or course of, permitting its customers to rapidly perceive and take motion as required based mostly on these occasions. In a whole lot of these case, methods like these are constructed in-house by combining completely different items of know-how together with streaming pipelines, lakes and warehouses. In relation to serving queries, this wants an analytics backend that has the next properties:

  1. Quick Ingestion — Even with lots of of 1000’s of occasions flowing each second, a backend to facilitate occasion knowledge analytics should be capable to sustain with that price. Complicated offline ETL processes are usually not preferable as they’d add minutes to hours earlier than the info is on the market to question.
  2. Interactive Latencies — The system should enable ad-hoc queries and drilldowns in real-time. Generally understanding a sample within the occasions requires with the ability to group by completely different attributes within the occasions to try to perceive the correlations in real-time.
  3. Complicated Queries — The system should enable querying utilizing an expressive question language to permit expressing worth lookups, filtering on a predicate, combination features, and joins.
  4. Developer-Pleasant – The system should include libraries and SDKs that enable builders to jot down customized functions on prime of it, in addition to help dashboarding.
  5. Configurable and Scalable – This contains with the ability to management the time for which information are retained, variety of replicas of knowledge being queried, and with the ability to scale as much as help extra knowledge with minimal operational overhead.


Apache Druid is a column-oriented distributed knowledge retailer for serving quick queries over knowledge. Druid helps streaming knowledge sources, Apache Kafka and Amazon Kinesis, via an indexing service that takes knowledge coming in via these streams and ingests them, and batch ingestion from Hadoop and knowledge lakes for historic occasions. Instruments like Apache Superset are generally used to investigate and visualize the info in Druid. It’s attainable to configure aggregations in Druid that may be carried out at ingestion time to show a variety of information right into a single document that may then be written.


On this instance, we’re inserting a set of JSON occasions into Druid. Druid doesn’t natively help nested knowledge, so, we have to flatten arrays in our JSON occasions by offering a flattenspec, or by performing some preprocessing earlier than the occasion lands in it.


Druid assigns sorts to columns — string, lengthy, float, advanced, and so forth. The sort enforcement on the column degree might be restrictive if the incoming knowledge presents with combined sorts for a specific discipline/fields. Every column besides the timestamp might be of kind dimension or metric. One can filter and group by on dimension columns, however not on metric columns. This wants some forethought when selecting which columns to pre-aggregate and which of them will likely be used for slice-and-dice analyses.


Partition keys should be picked fastidiously for load-balancing and scaling up. Streaming new updates to the desk after creation requires utilizing one of many supported methods of ingesting – Kafka, Kinesis or Tranquility.

Druid works nicely for occasion analytics in environments the place the info is considerably predictable and rollups and pre-aggregations might be outlined a priori. It includes some upkeep and tuning overhead when it comes to engineering, however for occasion analytics that doesn’t contain advanced joins, it may serve queries with low latency and scale up as required.


  • Low latency analytical queries over the column retailer
  • Ingest time aggregations might help cut back quantity of knowledge written
  • Good help for SDKs and libraries in numerous programming languages
  • Works nicely with Hadoop
  • Kind enforcement on the column degree might be restrictive with combined sorts
  • Medium to excessive operational overhead at scale
  • Estimating assets and capability planning is troublesome at scale
  • Lacks help for nested knowledge natively
  • Lacks help for SQL JOINs



Elasticsearch is a search and analytics engine that may also be used for queries over occasion knowledge. Hottest for queries over system and machine logs for its full-text search capabilities, Elasticsearch can be utilized for advert hoc analytics in some particular instances. Constructed on prime of Apache Lucene, Elasticsearch is commonly used along with Logstash for ingesting knowledge, and Kibana as a dashboard for reporting on it. When used along with Kafka, the Kafka Join Elasticsearch sink connector is used to maneuver knowledge from Kafka to Elasticsearch.

Elasticsearch indexes the ingested knowledge, and these indexes are usually replicated and are used to serve queries. The Elasticsearch question DSL is generally used for improvement functions, though there’s SQL help in X-Pack that helps some kinds of SQL analytical queries in opposition to indices in Elasticsearch. That is essential as a result of for occasion analytics, we need to question in a flexible method.


Elasticsearch SQL works nicely for fundamental SQL queries however can’t presently be used to question nested fields, or run queries that contain extra advanced analytics like relational JOINs. That is partly as a result of underlying knowledge mannequin.

It’s attainable to make use of Elasticsearch for some fundamental occasion analytics and Kibana is a wonderful visible exploration instrument with it. Nonetheless, the restricted help for SQL implies that the info might have to be preprocessed earlier than it may be queried successfully. Additionally, there’s non-trivial overhead in operating and sustaining the ingestion pipeline and Elasticsearch itself because it scales up. Due to this fact, whereas it suffices for fundamental analytics and reporting, its knowledge mannequin and restricted question capabilities make it fall wanting being a completely featured analytics engine for occasion knowledge.


  • Glorious help for full-text search
  • Extremely performant for level lookups due to inverted index
  • Wealthy SDKs and library help
  • Lacks help for JOINs
  • SQL help for analytical queries is nascent and never totally featured
  • Excessive operational overhead at scale
  • Estimating assets and capability planning is troublesome



Rockset is a backend for occasion stream analytics that can be utilized to construct customized instruments that facilitate visualizing, understanding, and drilling down. Constructed on prime of RocksDB, it’s optimized for operating search and analytical queries over tens to lots of of terabytes of occasion knowledge.

Ingesting occasions into Rockset might be achieved by way of integrations that require nothing greater than learn permissions once they’re within the cloud, or straight by writing into Rockset utilizing the JSON Write API.


These occasions are processed inside seconds, listed and made accessible for querying. It’s attainable to pre-process knowledge utilizing discipline mappings and SQL-function-based transformations throughout ingestion time. Nonetheless, no preprocessing is required for any advanced occasion construction — with native help for nested fields and mixed-type columns.

Rockset helps utilizing SQL with the flexibility to execute advanced JOINs. There are APIs and language libraries that permit customized code hook up with Rockset and use SQL to construct an utility that may do customized drilldowns and different customized options. Utilizing Rockset”s Converged Index™, ad-hoc queries run to completion very quick.

Making use of the ALT structure, the system robotically scales up completely different tiers—ingest, storage and compute—as the dimensions of the info or the question load grows when constructing a customized dashboard or utility function, thereby eradicating a lot of the want for capability planning and operational overhead. It doesn’t require partition or shard administration, or tuning as a result of optimizations and scaling are robotically dealt with beneath the hood.

For quick ad-hoc analytics over real-time occasion knowledge, Rockset might help by serving queries utilizing full SQL, and connectors to instruments like Tableau, Redash, Superset and Grafana, in addition to programmatic entry by way of REST APIs and SDKs in numerous languages.


  • Optimized for level lookups in addition to advanced analytical queries
  • Help for full SQL together with distributed JOINs
  • Constructed-in connectors to streams and knowledge lakes
  • No capability estimation wanted – scales robotically
  • Helps SDKs and libraries in numerous programming languages
  • Low operational overhead
  • Free eternally for small datasets
  • Supplied as a managed service

Go to our Kafka options web page for extra data on constructing real-time dashboards and APIs on Kafka occasion streams.


Leave a Reply