SlideShare a Scribd company logo
Scaling near-realtime
analytics with Kafka and
HBase
OSCON 2012
Dave Revell & Nate Putnam
Urban Airship
About Us

•   Nate Putnam
    •   Team Lead, Core Data and Analytics (1 year)
    •   Previously Engineer at Jive Software (4 years)
    •   Contributor to HBase/Zookeeper
•   Dave Revell
    •   Database Engineer, Core Data and Analytics (1 year)
    •   Previously Engineer at Meebo (1 year)
    •   HBase contributor
In this Talk

•   About Urban Airship
•   Why near-realtime?
•   About Kafka
•   Data Consumption
•   Scheduling
•   HBase / High speed counting
•   Questions
What is an Urban Airship?
•   Hosting for mobile services that developers should not
    build themselves
•   Unified API for services across platforms
•   SLAs for throughput, latency
By The Numbers
By The Numbers



•   Hundreds of millions devices
By The Numbers



•   Hundreds of millions devices
•   Front end API sustains thousands of requests per
    second
By The Numbers



•   Hundreds of millions devices
•   Front end API sustains thousands of requests per
    second
•   Millions of Android devices online all the time
By The Numbers



•   Hundreds of millions devices
•   Front end API sustains thousands of requests per
    second
•   Millions of Android devices online all the time
•   6 months for the company to deliver 1M messages,
    hundred million plus a day now.
Pretty Graphs
Near-Realtime?



•   Realtime or Really fast?
•   Events happen async
•   Realtime failure scenarios are hard
•   In practice a few minutes is all right for analytics
Overview

  Kafka-0



  Kafka-1    Consumer-0


  Kafka-2   Memory Queue   Worker-0


                           Indexer-0


                           Indexer-1   HBase


                           Indexer-2
Kafka


•   Created by the SNA Team @ LinkedIn
•   Publish-Subscribe system with minimal features
•   Can keep as many messages buffered as you have disk
    space
•   Fast with some trade offs
Kafka

•   Topics are partitioned across servers
•   Partitioning scheme is customizable


            Topic_0         Topic_0         Topic_0
             partition_0     partition_4     partition_8

             partition_1     partition_5     partition_9

             partition_2     partition_6    partition_10

             partition_3     partition_7    partition_11
Kafka

•   Consumption is 1 thread per distinct partition
•   Consumers keep track of their own offsets
      Time




                                    Topic_0, Consumer Group 1
                                    Partition 0, Offset : 7




                                                  Topic_0, Consumer Group 1
                                                  Partition 1, Offset : 10




             Topic_0, Consumer Group 1
             Partition 3, Offset : 2
Kafka



•   Manipulation of time based indexes is powerful
•   Monitor offsets and lag
•   Throw as much disk at this as you can
•   http://incubator.apache.org/kafka/
Consumers



•   Mirror Kafka design
•   Lots of parallelism to increase throughput
•   Share nothing
•   No ordering guarantees
Consumers

  Kafka-0



  Kafka-1    Consumer-0


  Kafka-2   Memory Queue   Worker-0


                           Indexer-0


                           Indexer-1   HBase


                           Indexer-2
Consumers


  Kafka-0



  Kafka-1    Consumer-0


  Kafka-2   Memory Queue   Worker-0


                           Indexer-0


                           Indexer-1   HBase


                           Indexer-2
Consumers

    partition_0

    partition_1
    partition_2

    partition_3
                   Consumer-0   Queue
    partition_4

    partition_5    Consumer-1   Queue

    partition_6
                   Consumer-2   Queue
    partition_7

                   Consumer-3   Queue
    partition_8
    partition_9

    partition_10
    partition_11
Consumers

  Kafka-0



  Kafka-1    Consumer-0



  Kafka-2   Memory Queue   Worker-0


                           Indexer-0


                           Indexer-1   HBase


                           Indexer-2
Consumers

            Worker-0   Indexer-0


            Worker-1
                       Indexer-1

            Worker-2
    Queue              Indexer-2

            Worker-3
                       Indexer-3
            Worker-4               HBase

                       Indexer-4
            Worker-5

                       Indexer-5


                       Indexer-6


                       Indexer-7
Scheduled aggregation tasks


•   Challenge: aggregate values that arrive out of order
•   Example: sessions/clickstream
•   Two steps:
                                   t6   t4   t5   t7   t3   t8   t1   t9   t2   t0

    •   Quickly write into HBase
    •   Periodically scan to
        calculate aggregates
Events arrive in arbitrary order


                    t6   t4      t5    t7    t3    t8   t1   t9   t2   t0

     Initially we
     store in an
        HBase
      table with
     timestamp
        as key
                    t0   t1      t2    t3    t4    t5   t6   t7   t8   t9


                              Time-ordered on disk

S = session start   S     E      S     S     E     E    S    E    S    S
E = session end


                              Scheduled task scans
                              sequentially and infers
                                    sessions
Events arrive in arbitrary order


                    t6   t4      t5    t7    t3    t8   t1   t9   t2   t0

     Initially we
     store in an
        HBase
      table with
     timestamp
        as key
                    t0   t1      t2    t3    t4    t5   t6   t7   t8   t9


                              Time-ordered on disk

S = session start   S     E      S     S     E     E    S    E    S    S
E = session end


                              Scheduled task scans
                              sequentially and infers
                                    sessions
Events arrive in arbitrary order


                    t6   t4      t5    t7    t3    t8   t1   t9   t2   t0

     Initially we
     store in an
        HBase
      table with
     timestamp
        as key
                    t0   t1      t2    t3    t4    t5   t6   t7   t8   t9


                              Time-ordered on disk

S = session start   S     E      S     S     E     E    S    E    S    S
E = session end


                              Scheduled task scans
                              sequentially and infers
                                    sessions
Strengths



•   Efficient with disk and memory
•   Can tradeoff response time for disk usage
•   Fine granularity, 10Ks of jobs
Compared to MapReduce

                                                 Input data size
•   Similar to MapReduce shuffle:
    sequential IO, external sort          100

•   Fine grained failures, scheduling,    75
    resource allocation
                                          50
•   Can’t do lots of jobs, can’t do big
                                          25
    jobs
                                           0
•   But MapReduce is easier to use              Alice   Bob   Charlie Dave
Pro/con vs. realtime streaming


•   For example, a Storm topology
•   Challenge: avoid random reads
    (disk seeks) without keeping too   Bob's app,

    much state in RAM                   Devices
                                         10-20



•   Sorting minimizes state
•   But latency would be good
HBase




•   What it is
•   Why it’s good for low-latency big data
HBase

•   A database that uses HDFS for storage
•   Based on Google’s BigTable
•   Solves the problem “how do I query my Hadoop data?”
      •   Operations typically measured in milliseconds
      •   MapReduce is not suitable for real time queries
•   Scales well by adding servers (if you do everything right)
•   Not partition tolerant or eventually consistent
Why we like HBase



•   Scalable
•   Fast: millions of ops/sec
•   Open source, ASF top-level project
•   Strong community
HBase difficulties


•   Low level features, harder to use      Is it fast

    than RDBMS                             enough?



•   Hard to avoid accidentally             Identify

    introducing bottlenecks
                                          bottleneck




•   Garbage collection, JVM tuning      Rethink access
                                           patterns


•   HDFS
How to fail at HBase

•   Schema can limit scalability
                            HBase              HDFS

       KeyA                                  Datanode 1
                 Region 1
       KeyB
       KeyC
                 Region 2           Region
       KeyD
                                    Server   Datanode 2
       KeyE                           1
                 Region 3
       KeyF
       KeyG
                 Region 4                    Datanode 3
       KeyH
       KeyI
                 Region 5
       KeyJ
                                    Region
       KeyK                         Server   Datanode 4
                 Region 6             2
       KeyL
       KeyM
                 Region 7
       KeyN
Troubleshooting
•   Isolate slow regions or servers with statshtable
    •      http://github.com/urbanairship/statshtable



                        HBase              HDFS

    KeyA                                 Datanode 1
             Region 1
    KeyB
    KeyC
             Region 2           Region
    KeyD
                                Server   Datanode 2
    KeyE                          1
             Region 3
    KeyF
    KeyG
             Region 4                    Datanode 3
    KeyH
    KeyI
             Region 5
    KeyJ
                                Region
    KeyK                        Server   Datanode 4
             Region 6             2
    KeyL
    KeyM
             Region 7
    KeyN
Counting


•   The main thing that we do
•   Scaling dimensions:
    •   Many counters of interest per event
    •   Many events
    •   Many changes to counter definitions
A naive attempt
for event in stream:
  user_id = extract_user_id(event)
  timestamp = extract_timestamp(event)
  event_type = extract_event_type(event)
  client_type = extract_client_type(event)
  location = extract_location(event)

 increment_event_type_count(event_type)
 increment_client_and_event_type_count(event_type, client_type)
 increment_user_id_and_event_type_count(user_id, event_type)
 increment_user_id_and_client_type_count(user_id, client_type)

 for time_precision in {HOURLY, DAILY, MONTHLY}:
   increment_time_count(time_precision, timestamp)
   increment_time_client_type_event_type_count(time_precision, ..)
   increment_(...)

   for location_precision in {CITY, STATE, COUNTRY}:
     increment_time_location_event_type_client_type_user_id(...)

     for bucket in yet_another_dimension: ....
Counting with datacubes



•   Challenge: count items in a stream matching various
    criteria, when criteria may change
•   github.com/urbanairship/datacube
•   A Java library for turning
    streams into OLAP cubes
    •   Especially multidimensional counters
The data cube                                                    n
 abstraction                                                 s io
                                                           en
                                                       m
                                                   t di
                                                 en




                                                      An
                                               ag                                      5
                                          er




                                                   dr
                                        s




                                                      oid
                                    U




                                                       IO
                                                          S
                                                                            2
                          7/15/12 00:00          24            11     3           10
      Hourly buckets      7/15/12 01:00                               5
                       … more hourly rows...                          ...
   Time Dimension
                         7/15/12 00:00:00                             8
       Daily buckets     7/16/12 00:00:00                             0
                       … more daily rows...                           ...


                                                                      8
      Not shown: many more dimensions                        Alice   Bob        Charlie

                                                               User ID dimension
Why datacube?

•   Handles exponential number of writes
•   Async IO with batching
•   Declarative interface: say what to count, not how
•   Pluggable database backend (currently HBase)
•   Bulk loader
•   Easily change/extend online cubes
Datacube isn’t just for counters




 Courtesy Tim Robertson, GBIF

github.com/urbanairship/datacube
Courtesy Tim Robertson, GBIF

github.com/urbanairship/datacube
Questions?
Thanks!



•   HBase and Kafka for being awesome
•   We’re hiring! urbanairship.com/jobs/
•   @nateputnam @dave_revell

More Related Content

What's hot (20)

PPTX
Apache Kafka
Joe Stein
 
PPTX
Visualizing Kafka Security
DataWorks Summit
 
PDF
HBaseCon 2013: Apache HBase, Meet Ops. Ops, Meet Apache HBase.
Cloudera, Inc.
 
PPTX
Data Architectures for Robust Decision Making
Gwen (Chen) Shapira
 
PPTX
Kafka blr-meetup-presentation - Kafka internals
Ayyappadas Ravindran (Appu)
 
PDF
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
confluent
 
PPTX
HBaseCon 2012 | HBase, the Use Case in eBay Cassini
Cloudera, Inc.
 
PPTX
HBaseCon 2012 | Building a Large Search Platform on a Shoestring Budget
Cloudera, Inc.
 
PPTX
Optimizing Apache HBase for Cloud Storage in Microsoft Azure HDInsight
HBaseCon
 
PDF
C* Summit 2013: Time for a New Relationship - Intuit's Journey from RDBMS to ...
DataStax Academy
 
PPTX
Emerging technologies /frameworks in Big Data
Rahul Jain
 
PPTX
Real-Time Distributed and Reactive Systems with Apache Kafka and Apache Accumulo
Joe Stein
 
PPTX
January 2015 HUG: Using HBase Co-Processors to Build a Distributed, Transacti...
Yahoo Developer Network
 
PPTX
Cross-Site BigTable using HBase
HBaseCon
 
PPTX
Have your cake and eat it too
Gwen (Chen) Shapira
 
PDF
Apache Drill (ver. 0.1, check ver. 0.2)
Camuel Gilyadov
 
PDF
Kafka to the Maxka - (Kafka Performance Tuning)
DataWorks Summit
 
PPTX
[Hadoop Meetup] Apache Hadoop 3 community update - Rohith Sharma
Newton Alex
 
PDF
Kudu - Fast Analytics on Fast Data
Ryan Bosshart
 
PDF
DatEngConf SF16 - Apache Kudu: Fast Analytics on Fast Data
Hakka Labs
 
Apache Kafka
Joe Stein
 
Visualizing Kafka Security
DataWorks Summit
 
HBaseCon 2013: Apache HBase, Meet Ops. Ops, Meet Apache HBase.
Cloudera, Inc.
 
Data Architectures for Robust Decision Making
Gwen (Chen) Shapira
 
Kafka blr-meetup-presentation - Kafka internals
Ayyappadas Ravindran (Appu)
 
From Message to Cluster: A Realworld Introduction to Kafka Capacity Planning
confluent
 
HBaseCon 2012 | HBase, the Use Case in eBay Cassini
Cloudera, Inc.
 
HBaseCon 2012 | Building a Large Search Platform on a Shoestring Budget
Cloudera, Inc.
 
Optimizing Apache HBase for Cloud Storage in Microsoft Azure HDInsight
HBaseCon
 
C* Summit 2013: Time for a New Relationship - Intuit's Journey from RDBMS to ...
DataStax Academy
 
Emerging technologies /frameworks in Big Data
Rahul Jain
 
Real-Time Distributed and Reactive Systems with Apache Kafka and Apache Accumulo
Joe Stein
 
January 2015 HUG: Using HBase Co-Processors to Build a Distributed, Transacti...
Yahoo Developer Network
 
Cross-Site BigTable using HBase
HBaseCon
 
Have your cake and eat it too
Gwen (Chen) Shapira
 
Apache Drill (ver. 0.1, check ver. 0.2)
Camuel Gilyadov
 
Kafka to the Maxka - (Kafka Performance Tuning)
DataWorks Summit
 
[Hadoop Meetup] Apache Hadoop 3 community update - Rohith Sharma
Newton Alex
 
Kudu - Fast Analytics on Fast Data
Ryan Bosshart
 
DatEngConf SF16 - Apache Kudu: Fast Analytics on Fast Data
Hakka Labs
 

Viewers also liked (20)

PDF
Event-Stream Processing with Kafka
Tim Lossen
 
PDF
Realtime Analytics with Hadoop and HBase
larsgeorge
 
PDF
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
mumrah
 
PDF
Real-time Analytics with HBase (short version)
alexbaranau
 
PDF
HBaseCon 2012 | HBase Schema Design - Ian Varley, Salesforce
Cloudera, Inc.
 
PPTX
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Christopher Curtin
 
PDF
HBase Applications - Atlanta HUG - May 2014
larsgeorge
 
PDF
HBase Status Report - Hadoop Summit Europe 2014
larsgeorge
 
PDF
HBase Storage Internals
DataWorks Summit
 
PDF
HBase for Architects
Nick Dimiduk
 
PDF
Intro to HBase Internals & Schema Design (for HBase users)
alexbaranau
 
PPTX
HBase and HDFS: Understanding FileSystem Usage in HBase
enissoz
 
ODP
Apache Kafka Demo
Edward Capriolo
 
PDF
Transactional Streaming: If you can compute it, you can probably stream it.
jhugg
 
PDF
Cgc2 cdn gamingsummit-real-time-customer-analytics
brock55
 
PDF
Real Time Recommendation System using Kiji
Daqing Zhao
 
PPTX
HBase: Extreme makeover
bigbase
 
PDF
TDWI Solution Summit San Diego 2014 Advanced Analytics at Macys.com
Daqing Zhao
 
PDF
Realtime Analytics With Elasticsearch [New Media Inspiration 2013]
Karel Minarik
 
PDF
Feeding Cassandra with Spark-Streaming and Kafka
DataStax Academy
 
Event-Stream Processing with Kafka
Tim Lossen
 
Realtime Analytics with Hadoop and HBase
larsgeorge
 
Introduction and Overview of Apache Kafka, TriHUG July 23, 2013
mumrah
 
Real-time Analytics with HBase (short version)
alexbaranau
 
HBaseCon 2012 | HBase Schema Design - Ian Varley, Salesforce
Cloudera, Inc.
 
Kafka 0.8.0 Presentation to Atlanta Java User's Group March 2013
Christopher Curtin
 
HBase Applications - Atlanta HUG - May 2014
larsgeorge
 
HBase Status Report - Hadoop Summit Europe 2014
larsgeorge
 
HBase Storage Internals
DataWorks Summit
 
HBase for Architects
Nick Dimiduk
 
Intro to HBase Internals & Schema Design (for HBase users)
alexbaranau
 
HBase and HDFS: Understanding FileSystem Usage in HBase
enissoz
 
Apache Kafka Demo
Edward Capriolo
 
Transactional Streaming: If you can compute it, you can probably stream it.
jhugg
 
Cgc2 cdn gamingsummit-real-time-customer-analytics
brock55
 
Real Time Recommendation System using Kiji
Daqing Zhao
 
HBase: Extreme makeover
bigbase
 
TDWI Solution Summit San Diego 2014 Advanced Analytics at Macys.com
Daqing Zhao
 
Realtime Analytics With Elasticsearch [New Media Inspiration 2013]
Karel Minarik
 
Feeding Cassandra with Spark-Streaming and Kafka
DataStax Academy
 
Ad

Similar to Near-realtime analytics with Kafka and HBase (20)

PDF
Facebook Messages & HBase
强 王
 
PDF
Facebook keynote-nicolas-qcon
Yiwei Ma
 
PDF
支撑Facebook消息处理的h base存储系统
yongboy
 
PDF
Scaling HDFS to Manage Billions of Files
Haohui Mai
 
PDF
Scaling HDFS to Manage Billions of Files with Key-Value Stores
DataWorks Summit
 
PDF
Kudu austin oct 2015.pptx
Felicia Haggarty
 
PPTX
L6.sp17.pptx
SudheerKumar499932
 
PPTX
Zero-downtime Hadoop/HBase Cross-datacenter Migration
Scott Miao
 
PPTX
Hic 2011 realtime_analytics_at_facebook
baggioss
 
PDF
Hbase schema design and sizing apache-con europe - nov 2012
Chris Huang
 
PPTX
HBase Low Latency, StrataNYC 2014
Nick Dimiduk
 
PPTX
Hanborq optimizations on hadoop map reduce 20120221a
Schubert Zhang
 
PDF
HBase Advanced - Lars George
JAX London
 
PDF
Scaling ingest pipelines with high performance computing principles - Rajiv K...
SignalFx
 
PPTX
Hanborq Optimizations on Hadoop MapReduce
Hanborq Inc.
 
PDF
Hbase: an introduction
Jean-Baptiste Poullet
 
PPTX
HBase: Where Online Meets Low Latency
HBaseCon
 
PDF
Xldb2011 tue 0940_facebook_realtimeanalytics
liqiang xu
 
PPTX
Big Data and Hadoop - History, Technical Deep Dive, and Industry Trends
Esther Kundin
 
PDF
Facebook's HBase Backups - StampedeCon 2012
StampedeCon
 
Facebook Messages & HBase
强 王
 
Facebook keynote-nicolas-qcon
Yiwei Ma
 
支撑Facebook消息处理的h base存储系统
yongboy
 
Scaling HDFS to Manage Billions of Files
Haohui Mai
 
Scaling HDFS to Manage Billions of Files with Key-Value Stores
DataWorks Summit
 
Kudu austin oct 2015.pptx
Felicia Haggarty
 
L6.sp17.pptx
SudheerKumar499932
 
Zero-downtime Hadoop/HBase Cross-datacenter Migration
Scott Miao
 
Hic 2011 realtime_analytics_at_facebook
baggioss
 
Hbase schema design and sizing apache-con europe - nov 2012
Chris Huang
 
HBase Low Latency, StrataNYC 2014
Nick Dimiduk
 
Hanborq optimizations on hadoop map reduce 20120221a
Schubert Zhang
 
HBase Advanced - Lars George
JAX London
 
Scaling ingest pipelines with high performance computing principles - Rajiv K...
SignalFx
 
Hanborq Optimizations on Hadoop MapReduce
Hanborq Inc.
 
Hbase: an introduction
Jean-Baptiste Poullet
 
HBase: Where Online Meets Low Latency
HBaseCon
 
Xldb2011 tue 0940_facebook_realtimeanalytics
liqiang xu
 
Big Data and Hadoop - History, Technical Deep Dive, and Industry Trends
Esther Kundin
 
Facebook's HBase Backups - StampedeCon 2012
StampedeCon
 
Ad

Recently uploaded (20)

PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Python basic programing language for automation
DanialHabibi2
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
"Autonomy of LLM Agents: Current State and Future Prospects", Oles` Petriv
Fwdays
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Python basic programing language for automation
DanialHabibi2
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

Near-realtime analytics with Kafka and HBase

  • 1. Scaling near-realtime analytics with Kafka and HBase OSCON 2012 Dave Revell & Nate Putnam Urban Airship
  • 2. About Us • Nate Putnam • Team Lead, Core Data and Analytics (1 year) • Previously Engineer at Jive Software (4 years) • Contributor to HBase/Zookeeper • Dave Revell • Database Engineer, Core Data and Analytics (1 year) • Previously Engineer at Meebo (1 year) • HBase contributor
  • 3. In this Talk • About Urban Airship • Why near-realtime? • About Kafka • Data Consumption • Scheduling • HBase / High speed counting • Questions
  • 4. What is an Urban Airship? • Hosting for mobile services that developers should not build themselves • Unified API for services across platforms • SLAs for throughput, latency
  • 6. By The Numbers • Hundreds of millions devices
  • 7. By The Numbers • Hundreds of millions devices • Front end API sustains thousands of requests per second
  • 8. By The Numbers • Hundreds of millions devices • Front end API sustains thousands of requests per second • Millions of Android devices online all the time
  • 9. By The Numbers • Hundreds of millions devices • Front end API sustains thousands of requests per second • Millions of Android devices online all the time • 6 months for the company to deliver 1M messages, hundred million plus a day now.
  • 11. Near-Realtime? • Realtime or Really fast? • Events happen async • Realtime failure scenarios are hard • In practice a few minutes is all right for analytics
  • 12. Overview Kafka-0 Kafka-1 Consumer-0 Kafka-2 Memory Queue Worker-0 Indexer-0 Indexer-1 HBase Indexer-2
  • 13. Kafka • Created by the SNA Team @ LinkedIn • Publish-Subscribe system with minimal features • Can keep as many messages buffered as you have disk space • Fast with some trade offs
  • 14. Kafka • Topics are partitioned across servers • Partitioning scheme is customizable Topic_0 Topic_0 Topic_0 partition_0 partition_4 partition_8 partition_1 partition_5 partition_9 partition_2 partition_6 partition_10 partition_3 partition_7 partition_11
  • 15. Kafka • Consumption is 1 thread per distinct partition • Consumers keep track of their own offsets Time Topic_0, Consumer Group 1 Partition 0, Offset : 7 Topic_0, Consumer Group 1 Partition 1, Offset : 10 Topic_0, Consumer Group 1 Partition 3, Offset : 2
  • 16. Kafka • Manipulation of time based indexes is powerful • Monitor offsets and lag • Throw as much disk at this as you can • http://incubator.apache.org/kafka/
  • 17. Consumers • Mirror Kafka design • Lots of parallelism to increase throughput • Share nothing • No ordering guarantees
  • 18. Consumers Kafka-0 Kafka-1 Consumer-0 Kafka-2 Memory Queue Worker-0 Indexer-0 Indexer-1 HBase Indexer-2
  • 19. Consumers Kafka-0 Kafka-1 Consumer-0 Kafka-2 Memory Queue Worker-0 Indexer-0 Indexer-1 HBase Indexer-2
  • 20. Consumers partition_0 partition_1 partition_2 partition_3 Consumer-0 Queue partition_4 partition_5 Consumer-1 Queue partition_6 Consumer-2 Queue partition_7 Consumer-3 Queue partition_8 partition_9 partition_10 partition_11
  • 21. Consumers Kafka-0 Kafka-1 Consumer-0 Kafka-2 Memory Queue Worker-0 Indexer-0 Indexer-1 HBase Indexer-2
  • 22. Consumers Worker-0 Indexer-0 Worker-1 Indexer-1 Worker-2 Queue Indexer-2 Worker-3 Indexer-3 Worker-4 HBase Indexer-4 Worker-5 Indexer-5 Indexer-6 Indexer-7
  • 23. Scheduled aggregation tasks • Challenge: aggregate values that arrive out of order • Example: sessions/clickstream • Two steps: t6 t4 t5 t7 t3 t8 t1 t9 t2 t0 • Quickly write into HBase • Periodically scan to calculate aggregates
  • 24. Events arrive in arbitrary order t6 t4 t5 t7 t3 t8 t1 t9 t2 t0 Initially we store in an HBase table with timestamp as key t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 Time-ordered on disk S = session start S E S S E E S E S S E = session end Scheduled task scans sequentially and infers sessions
  • 25. Events arrive in arbitrary order t6 t4 t5 t7 t3 t8 t1 t9 t2 t0 Initially we store in an HBase table with timestamp as key t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 Time-ordered on disk S = session start S E S S E E S E S S E = session end Scheduled task scans sequentially and infers sessions
  • 26. Events arrive in arbitrary order t6 t4 t5 t7 t3 t8 t1 t9 t2 t0 Initially we store in an HBase table with timestamp as key t0 t1 t2 t3 t4 t5 t6 t7 t8 t9 Time-ordered on disk S = session start S E S S E E S E S S E = session end Scheduled task scans sequentially and infers sessions
  • 27. Strengths • Efficient with disk and memory • Can tradeoff response time for disk usage • Fine granularity, 10Ks of jobs
  • 28. Compared to MapReduce Input data size • Similar to MapReduce shuffle: sequential IO, external sort 100 • Fine grained failures, scheduling, 75 resource allocation 50 • Can’t do lots of jobs, can’t do big 25 jobs 0 • But MapReduce is easier to use Alice Bob Charlie Dave
  • 29. Pro/con vs. realtime streaming • For example, a Storm topology • Challenge: avoid random reads (disk seeks) without keeping too Bob's app, much state in RAM Devices 10-20 • Sorting minimizes state • But latency would be good
  • 30. HBase • What it is • Why it’s good for low-latency big data
  • 31. HBase • A database that uses HDFS for storage • Based on Google’s BigTable • Solves the problem “how do I query my Hadoop data?” • Operations typically measured in milliseconds • MapReduce is not suitable for real time queries • Scales well by adding servers (if you do everything right) • Not partition tolerant or eventually consistent
  • 32. Why we like HBase • Scalable • Fast: millions of ops/sec • Open source, ASF top-level project • Strong community
  • 33. HBase difficulties • Low level features, harder to use Is it fast than RDBMS enough? • Hard to avoid accidentally Identify introducing bottlenecks bottleneck • Garbage collection, JVM tuning Rethink access patterns • HDFS
  • 34. How to fail at HBase • Schema can limit scalability HBase HDFS KeyA Datanode 1 Region 1 KeyB KeyC Region 2 Region KeyD Server Datanode 2 KeyE 1 Region 3 KeyF KeyG Region 4 Datanode 3 KeyH KeyI Region 5 KeyJ Region KeyK Server Datanode 4 Region 6 2 KeyL KeyM Region 7 KeyN
  • 35. Troubleshooting • Isolate slow regions or servers with statshtable • http://github.com/urbanairship/statshtable HBase HDFS KeyA Datanode 1 Region 1 KeyB KeyC Region 2 Region KeyD Server Datanode 2 KeyE 1 Region 3 KeyF KeyG Region 4 Datanode 3 KeyH KeyI Region 5 KeyJ Region KeyK Server Datanode 4 Region 6 2 KeyL KeyM Region 7 KeyN
  • 36. Counting • The main thing that we do • Scaling dimensions: • Many counters of interest per event • Many events • Many changes to counter definitions
  • 37. A naive attempt for event in stream: user_id = extract_user_id(event) timestamp = extract_timestamp(event) event_type = extract_event_type(event) client_type = extract_client_type(event) location = extract_location(event) increment_event_type_count(event_type) increment_client_and_event_type_count(event_type, client_type) increment_user_id_and_event_type_count(user_id, event_type) increment_user_id_and_client_type_count(user_id, client_type) for time_precision in {HOURLY, DAILY, MONTHLY}: increment_time_count(time_precision, timestamp) increment_time_client_type_event_type_count(time_precision, ..) increment_(...) for location_precision in {CITY, STATE, COUNTRY}: increment_time_location_event_type_client_type_user_id(...) for bucket in yet_another_dimension: ....
  • 38. Counting with datacubes • Challenge: count items in a stream matching various criteria, when criteria may change • github.com/urbanairship/datacube • A Java library for turning streams into OLAP cubes • Especially multidimensional counters
  • 39. The data cube n abstraction s io en m t di en An ag 5 er dr s oid U IO S 2 7/15/12 00:00 24 11 3 10 Hourly buckets 7/15/12 01:00 5 … more hourly rows... ... Time Dimension 7/15/12 00:00:00 8 Daily buckets 7/16/12 00:00:00 0 … more daily rows... ... 8 Not shown: many more dimensions Alice Bob Charlie User ID dimension
  • 40. Why datacube? • Handles exponential number of writes • Async IO with batching • Declarative interface: say what to count, not how • Pluggable database backend (currently HBase) • Bulk loader • Easily change/extend online cubes
  • 41. Datacube isn’t just for counters Courtesy Tim Robertson, GBIF github.com/urbanairship/datacube
  • 42. Courtesy Tim Robertson, GBIF github.com/urbanairship/datacube
  • 44. Thanks! • HBase and Kafka for being awesome • We’re hiring! urbanairship.com/jobs/ • @nateputnam @dave_revell

Editor's Notes