SlideShare a Scribd company logo
1 of 189
Download to read offline
HBase Schema Design
HBase Schema Design
   How I Learned To Stop
    Worrying And Love
     Denormalization
What Is Schema Design?
Who am I?
            Ian Varley
Software engineer at Salesforce.com
          @thefutureian
What Is Schema Design?
   Logical Data Modeling
What Is Schema Design?
   Logical Data Modeling
             +
  Physical Implementation
You always start with a logical model.
   Even if it's just an implicit one.
        That's totally fine. (If you're right.)
There are lots of ways to model data.
     The most common one is:

      Entity / Attribute / Relationship

       (This is probably what you know
         of as just "data modeling".)
There's a well established visual
  language for data modeling.
Entities are boxes.
With rounded corners if you're fancy.
Attributes are listed vertically in the box.
       Optionally with data types, for clarity.
Relationships are connecting lines.
Optionally with special endpoints, and/or verbs
Example: Concerts
Example: Concerts
Example: Concerts



 A note about diagrams: they're useful
 for communicating, but can be more
  trouble than they're worth. Don't do
them out of obligation; only do them to
    understand your problem better.
Example: Concerts

 Entity



Attribute
Relationship
For relational databases, you usually
 start with this normalized model,
           then plug & chug.
For relational databases, you usually
 start with this normalized model,
           then plug & chug.
             Entities → Tables
          Attributes → Columns
       Relationships → Foreign Keys
       Many-to-many → Junction tables
        Natural keys → Artificial IDs
So, what's missing?
So, what's missing?
       If your data is not massive,
            NOTHING.
You should use a relational database. They rock*
So, what's missing?
                     If your data is not massive,
                                 NOTHING.
    You should use a relational database. They rock*
* - This statement has not been approved by the HBase product management committee, and neglects known
deficiencies with the relational model such as poor modeling of hierarchies and graphs, overly rigid attribute structure
enforcement, neglect of the time dimension, and physical optimization concerns leaking into the conceptual
abstraction.
Relational DBs work well because they
 are close to the pure logical model.
    That model is less likely to change as your
  business needs change. You may want to ask
  different questions over time, but if you got the
  logical model correct, you'll have the answers.
Ah, but what if you do have massive
    data? Then what's missing?
Problem: The relational model
 doesn't acknowledge scale.
Problem: The relational model
 doesn't acknowledge scale.

  "It's an implementation concern;
you shouldn't have to worry about it."
The trouble is, you do have
to worry about it. So you...
   ● Add indexes
   ● Add hints
   ● Write really complex, messy SQL
   ● Memorize books by Tom Kyte & Joe Celko
   ● Bow down to the optimizer!
   ● Denormalize
   ● Cache
   ● etc ...
Generally speaking, you poke holes in
 the abstraction, and it starts leaking.
So then you hear about this thing
  called NoSQL. Can it help?
Maybe. But ultimately, it's just a
different way of physically representing
     your same logical data model.

  Some things are easier; some are much harder.

 If you haven't started by understanding your logical
            model, you're doing it wrong.
HBase Architecture: A Brief Recap
HBase Architecture: A Brief Recap
 • Scales by splitting all rows into regions
HBase Architecture: A Brief Recap
 • Scales by splitting all rows into regions
 • Each region is hosted by exactly one server
HBase Architecture: A Brief Recap
 • Scales by splitting all rows into regions
 • Each region is hosted by exactly one server
 • Writes are held (sorted) in memory until flush
HBase Architecture: A Brief Recap
 • Scales by splitting all rows into regions
 • Each region is hosted by exactly one server
 • Writes are held (sorted) in memory until flush
 • Reads merge rows in memory with flushed files
HBase Architecture: A Brief Recap
 • Scales by splitting all rows into regions
 • Each region is hosted by exactly one server
 • Writes are held (sorted) in memory until flush
 • Reads merge rows in memory with flushed files
 • Reads & writes to a single row are consistent
So what does data in HBase look like?
HBase Data Model: Brief Recap
HBase Data Model: Brief Recap
Table: design-time namespace, has many rows.
HBase Data Model: Brief Recap
Table: design-time namespace, has many rows.
   Row: atomic byte array, with one row key
HBase Data Model: Brief Recap
Table: design-time namespace, has many rows.
   Row: atomic byte array, with one row key

  Not just a bunch of bytes, dude! A k/v map!
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
 Value: a value in the k/v container inside a row
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
 Value: a value in the k/v container inside a row
HBase Data Model: Brief Recap
Hold up! What about
    Table: design-time namespace, has many rows.
       time?
   Row: atomic key/value container, with one row key
     Column: a key in the k/v container inside a row
     Value: a value in the k/v container inside a row
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
The "row" is atomic, and gets flushed
   to disk periodically. But it doesn't have
   to be flushed into just a single file!


  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
This "row" brokenatomic, and gets store
     It can be guy is up into different
   flushed to disk periodically. Butand
     files with different properties, it doesn't
   have to caninto just just a subset.
     reads be look at one file.


  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
This "row" brokenatomic, and gets store
        can is guy is up into Families".
     It This becalled "Column different It's
   flushed to disk periodically. want, and
     files inof an advancedyou Butoption, so
              whatever way design it doesn't
        kind be
   have to caninto just one file.at a subset.
     reads think too much about it yet.
        don't     choose to look


  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
This "row" brokenatomic, and gets store
        can is guy is up into Families".
     It This becalled "Column different It's
   flushed to disk periodically. want, and allows
               whatever performance Butoption, so
                                             it doesn't
         From the Percolator way by Google: "Bigtable
                             paper
     files inof an advancedyou characteristics of the
   have to caninto the one design subset.
        kind becontrol just
         users to                   file.
     reads by grouping amuch about a yet.
                    choose to columns into a locality
                                  look at it
        don't think too set of to think about CFs.
         table
         group." That's a good way


  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
Calling these "columns" is an unfortunate use
of terminology. They're not fixed; each row can
have different keys, and the names are not
defined at runtime. So you can represent
another axis of data (in the key of the
key/value pair). More on that later.

   HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
They're officially called "column qualifiers". But
many people just say "columns".

Or "CQ". Or "Quallie". Now you're one of the cool kids.




   HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
What data types are stored in key/value pairs?




  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
What data types are stored in key/value pairs?
                  It's all bytes.




  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
What data types are stored in key/value pairs?
Row keys, column names, values: arbitrary bytes




  HBase Data Model: Brief Recap
 Table: design-time namespace, has many rows.
Row: atomic key/value container, with one row key
Column Family: divide columns into physical files
 Column: a key in the k/v container inside a row
Timestamp: long milliseconds, sorted descending
Value: a time-versioned value in the k/v container
What data types are stored in key/value pairs?
 Row keys, column names, values: arbitrary bytes
Table and column family names: printable characters


   HBase Data Model: Brief Recap
  Table: design-time namespace, has many rows.
 Row: atomic key/value container, with one row key
 Column Family: divide columns into physical files
  Column: a key in the k/v container inside a row
 Timestamp: long milliseconds, sorted descending
 Value: a time-versioned value in the k/v container
What data types are stored in key/value pairs?
 Row keys, column names, values: arbitrary bytes
Table and column family names: printable characters
            Timestamps: long integers

   HBase Data Model: Brief Recap
  Table: design-time namespace, has many rows.
 Row: atomic key/value container, with one row key
 Column Family: divide columns into physical files
  Column: a key in the k/v container inside a row
 Timestamp: long milliseconds, sorted descending
 Value: a time-versioned value in the k/v container
HBase Data Model: Brief Recap
One more thing that bears repeating: every "cell" (i.e.
 the time-versioned value of one column in one row)
is stored "fully qualified" (with its full rowkey, column
         family, column name, etc.) on disk.
So now you know what's available.
 Now, how do you model things?
Let's start with the entity / attribute /
 relationship modeling paradigm,
  and see how far we get applying it to HBase.
A note about my example:
      it's for clarity, not realism.
 For bands & shows, there's not enough data to
warrant using HBase, even if you're tracking every
 show by every band for all of human history. It
            might be GB, but not TB.
So, back to entities (boxes).
   With fancy rounded corners.
What's that in HBase? A table, right?
What's that in HBase? A table, right?
      Dramatic foreshadowing: not always ...
And what do entities have?
Attributes!
Attributes!
For example: a "Band" entity might have a "Name" (with values like
 "Jonathan Coulton") and a "Genre" (with values like "Nerd Core")
Logically, attributes are unordered.
Their vertical position is meaningless. They're simply
             characteristics of the entity.
Attributes can be identifying.
i.e. they uniquely identify a particular instance of that entity.
Attributes can be identifying.
i.e. they uniquely identify a particular instance of that entity.




  Logical models usually leave this out, and identity is
implied (i.e. we just assume there's some set of attributes
  that's identifying, but we don't have to say what it is)
Attributes can be identifying.
 i.e. they uniquely identify a particular instance of that entity.


                          PK




Physical models refer to it explicitly, like how in a relational
database model you'd label some set of attributes as being
                the "Primary Key" (PK).
Attributes can be identifying.
i.e. they uniquely identify a particular instance of that entity.




  So in our Band example, neither Name nor Genre is
 uniquely identifying, but something like URL might be.
How does this map to HBase?
How does this map to HBase?
Identifying attributes (aka the "PK") become parts of
 the row key, and other attributes become columns.
So here's a Band schema.
The row key is the URL, and we have
   Name and Genre as attributes.
A much common pattern is to use IDs.
That way, you have an immutable way to refer to this
     entity forever, even if they leave MySpace.
A much common pattern is to use IDs.
  That way, you have an immutable way to refer to this
       entity forever, even if they leave MySpace.




Where do IDs come from? We'll talk about that later.
If there's just a single row key,
how can there be multiple identifying attributes?
Let's call that "mashing".
Which is to say, concatenation, in either a fixed-width
       or delimited manner, in the byte array.
Mashing includes several techniques:
      ● Fixed byte width representation
      ● Delimiting (for variable length)
      ● Other serialization (avro, etc.)
Mashing includes several techniques:
           ● Fixed byte width representation
           ● Delimiting (for variable length)
           ● Other serialization (avro, etc.)

Doesn't matter how you do it; the important thing is that any byte
 array in HBase can represent more than one logical attribute.
If we want, we can even add types to
       the schema definition.
If we want, we can even add types to
       the schema definition.
                            ?
If we want, we can even add types to
       the schema definition.
                              ?



                            HBase don't care,
                          but we do (sometimes).
If we want, we can even add types.
 You could also mark things as ASC or DESC,
  depending on whether you invert the bits.
                                     ?
This is pretty textbook stuff, but here's
         where it gets exciting.
This is pretty textbook stuff, but here's
         where it gets exciting.
      (If you're astute, you'll notice we haven't
           talked about relationships yet.)
HBase has no foreign keys, or joins, or
      cross-table transactions.
    This can make representing relationships
            between entities ... tricky.
Part of the beauty of the relational model
  is that you can punt on this question.
  If you model the entities as fully normalized, then you
  can write any query you want at run time, and the DB
      performs joins on tables as optimally as it can.

            (This relies heavily on indexing.)
In HBase (or any distributed DB)
     you don't have that luxury.
 Joins get way more expensive and complicated
across a distributed cluster of machines, as do the
   indexes that make them happen efficiently.

     HBase has neither joins nor indexes.
You have two choices, if you need
 relationships between entities.
You have two choices, if you need
 relationships between entities.
     ● Roll your own joins
You have two choices, if you need
 relationships between entities.
     ● Roll your own joins
     ● Denormalize the data
Rolling your own joins is hard.

        You'll probably get it wrong
         if you try to do it casually.

  Ever implemented a multi-way merge sort by hand?
Denormalizing is fun!

But it also sucks. We'll see why.
The basic concept of denormalization is simple:
           two logical entities share
        one physical representation.
The basic concept of denormalization is simple:
           two logical entities share
        one physical representation.

    Of course, there are lots of ways to skin a cat...
Let's look at standard relational database
     denormalization techniques first.
In a relational database, if the
normalized physical model is this:
You could start with the Band, and give it
   extra columns to hold the shows:
You could start with the Band, and give it
   extra columns to hold the shows:
That's pretty obviously a bad idea, because
       bands can play a lot of shows.




                         WTF?
You could also just give it an unstructured
      blob of text for all the shows.
You could also just give it an unstructured
      blob of text for all the shows.




                      But then you've given up
                      the integrity of your data.
                      (Which might be fine.
                      If so, stop here.)
You get similar problems if you try to bring
     all the info into the Show table.
Another solution is to focus
  on the junction table.
And pull in copies of the info
    in the other tables:
Leaving you with one table, with
one row per band/show combination:
The cons to this should be self-evident.
 Updating and querying are more complicated, because
you have to deal with many representations of the "same"
         data, which could get out of sync, etc.
But the pros are that with huge data,
answering some questions is much faster.
  (If you happen to be asking the query in the same way
        you structured the denormalization, that is.)
So back to HBase. How do you
denormalize in an HBase schema?
HBase columns can be defined at runtime.
A column doesn't have to represent a pre-defined attribute.
HBase columns can be defined at runtime.
A column doesn't have to represent a pre-defined attribute.
      In fact, it doesn't have to be an attribute at all.
A set of dynamically named columns
   can represent another entity!
If you put data into the column name,
   and expect many such columns in the same row,
    then logically, you've created a nested entity.
You can scan over columns.
See: hadoop-hbase.blogspot.com/2012/01/hbase-intra-row-scanning.html
So we can store shows inside bands.
   Which is like the denormalization we say earlier,
      except without the relational DB kludges.
Note!

               HBase don't care.
It's just a matter of how your app treats the columns. If you
    put repeating info in column names, you're doing this.
Why is this so difficult for most
  relational database devs to grok?
                        Because
relational databases have no concept of nested entities!

You'd make it a separate table in an RDBMS, which is more
       flexible but much more difficult to optimize.
It's very difficult to talk about HBase
schemas if you don't acknowledge this.
You don't have to represent it this way (with a nested box) but
  you have to at least acknowledge it. And maybe name it.
But, once you do acknowledge it,
       you can do some neat things.
Nested entities can have attributes,
       some of which are identifying.
Nested entities can have attributes,
               some of which are identifying.



Identifying attributes
make up the column
qualifier (just like
row keys, it could be
multiple attributes
mashed together)
Nested entities can have attributes,
               some of which are identifying.



Identifying attributes                Non-identifying
make up the column                    attributes are held
qualifier (just like                  in the value (again,
row keys, it could be                 you could mash
multiple attributes                   many attributes in
mashed together)                      here)
Shows is nested in Band
             show_id is the column qualifier
        Other attributes are mashed into the value




                                        Everything else
The column qualifier                    gets mashed into
is the show id.                         the value field.
1 table can have many nested entities,
     provided your app can tell them apart.
How do you tell them apart?
        With prefixes ...




         qualifier starts with:
         "s" + show_id
         "a" + album_id
         "m" + name
Where can you
nest entities?
Knock yourself out.
Where can you
nest entities?
Knock yourself out.

● In columns
Where can you
nest entities?
Knock yourself out.

● In columns
● Two levels deep in
  columns!
Where can you
nest entities?
Knock yourself out.

● In columns
● Two levels deep in
  columns!
● In the row key?!
Where can you
nest entities?
Knock yourself out.

● In columns
● Two levels deep in
  columns!
● In the row key?!
● Using timestamps as a
  dimension!!
This is a fundamental modeling
property of HBase: nesting entities.
Wait, what about Column Families?
They're just namespaces--additional
vertical sections on the same entity.
Where column families aren't shown
explicitly, let's assume there's just one.
So that brings us to a standard way to
           show an HBase schema:
Table: Top level entity name, fixed at design time.
Row key: Can consist of multiple parts, each with a
name & type. All data in one row shares the same
row key. Can be nested.
Column family: A container that allows sets of
columns to have separate storage & semantics.
Column qualifiers: Fixed attributes--design-time
named columns, holding a value of a certain type.
Nested entities: Run-time named column qualifiers,
where the qualifier is made up of one (or more)
values, each with a type, along with one or more
values (by timestamp) which also have a type.


Nested versions: Because multiple timestamped
copies of each value can exist, you can also treat the
timestamp as a modeled dimension in its own right.
Hell, you could even use a long that's not a
timestamp (like, say, an ID number). Caveats apply.
"But," you say, "what if I don't have all
   of these fancy modeling tools?"
Say it in text.
              XML, JSON, DML, whatever you like.

<table name="Band">
 <key>
   <column name="band_id" type="int" />
 </key>
 <columnFamily name="cf1">
   <column name="band_name" type="string"/>
   <column name="hometown" type="string"/>
   <entity name="Show">
    <key>
     <column name="show_id">
    </key>
    <column name="date" type="date" />
   </entity>
 </columnFamily>
</table>
Text is faster and more general, but
  slightly harder to grok quickly.
     So we'll stick with diagrams here.
Some examples are in order.
Example 1: a simple parent/child relationship
     Relational Schema: Applicants & Answers




Standard parent/child relationship. One Applicant has many
Answers; every Answer relates to a single Applicant (by id). It
also relates to a Question (not shown). SQL would have you JOIN
them to materialize an applicant and their answers.
HBase Schema: Answers By Applicant




● Answer is contained implicitly in Applicant
● If you know an applicant_id, you get O(1) access
● If you know an applicant_id AND question_id, O(1) access
● Answer.created_date is implicit in the timestamp on value
HBase Schema: Answers By Applicant




● You get answer history for free
● Applicant.applied_date can be implicit in the timestamp
● More attributes on applicant directly? Just add them!
● Answers are atomic and transactional by Applicant!!
Example of rows in HBase:
Before you get too excited, remember
that there are cons to denormalization.
The cons:
● Nested entities aren't independent any more.
   ○ No: "SELECT avg(value) FROM Answer WHERE question_id = 123;"
   ○ But you can still do that with map/reduce
● This decomposition only works in one direction.
   ○ No relation chains without serious trickery.
   ○ Timestamps are another dimension, but that counts as trickery.
● No way to enforce the foreign key to another table.
   ○ But would you really do that in a big RDBMS?
● On disk, it repeats the row key for every column
   ○ You didn't really save anything by having applicant_id be
     implied.
   ○ Or did you? Compression negates that on disk ...
   ○ ... and prefix compression (HBASE-4218) will totally sink this.
Example 2: dropping some database science
      Relational Schema: Users And Messages




Many-to-many relationship. One User sees many Messages, and
a single Message can be seen by many Users. We want to do
things like show the most recent message by subject (e.g. an inbox
view).
What kind of SQL would you run on this? Say, we
want to get the most recent 20 messages for 1 user.
    SELECT TOP 20
     M.subject,
     M.body
     FROM
      User_Message UM
      INNER JOIN Message M
       ON UM.message_id = M.message_id
     WHERE
      UM.user_id = <user_id>
     ORDER BY
      M.sent_date DESC
Seems easy, right? Well, the database is doing
         some stuff behind the scenes for you:
         Assuming no secondary indexes, it might:
           ● Drive the join from the User_Message table
           ● For each new record with our given user_id, do a single
             disk access into the Message table (i.e. a hash_join)
           ● Get the records for *every* message for this user
           ● Sort them all
           ● Take the top 20

No shortcuts; we can't find the top 20 by date w/o seeing ALL messages.

 This gets more expensive as a user gets more messages. (But it's still
   pretty fast if a given user has a reasonable number of messages).
How could you do this in HBase?
     Try the same pattern as parent / child?




1. Because of the many-to-many, you now have N copies
   of the message (one per user).
    ○ Maybe that's OK (especially if it's immutable!). Disk is cheap.
2. Your statement has to do the same amount of work, but
   now you have to do it yourself. :(
If I   know that I always want it ordered by date, why
                 not store it that way?




   ● Now I can scan over messages by date until I get
     enough; it's O(1)
   ● But what if I want it by message_id again? Doh.
     I'm screwed, unless ...
I store it both ways!




Nice: updates to this are transactional (consistent) for a given
user, because it's all in one row. So it's not a bear to maintain.
Which I could even do in different column families ...




(Makes sense if I don't usually access them at the same time; I only
            pay the cost for the query I am running.)
So, for example ...
Or I could just use the by-date one as an "index" ...




         So I only store the subject and body once.
    This means I need to perform my own "join" in code.
See a theme emerging?
  Relational DBs lull you into not thinking about physical
access as much; but when you have to scale, there are hard
                            limits.

 HBase makes you think about it sooner, but gives you the
   tools to think about it in more a straightforward way.
Example 3: Flurry
                     See: http://www.flurry.com/data/




                                    ● One row per device
                                    ● Nested entity in CF "Sessions"
                                        ○ Polymorphic "fragments"
                                          of session reports
                                        ○ Map/Reduce transforms




Caveat: this is based on email exchanges, so the details
may be wonky, but I think the overall point is right.
Example 4: Indexes
                        Example from Andrew Purtell




 ● Using one table as an index into another often makes sense
 ● Can't be transactional (without external coordination)
 ● So you have to keep it clean, or tolerate dirty indexes
 ● Note that there are several attempts to add solid general
   purpose indexing to HBase, but so far none have caught on.


Same caveat: this is based on email exchanges, so the
details may be wonky, but I think the overall point is right.
Here are some more design patterns.
0: The row key design is the single
most important decision you will make.
0: The row key design is the single
most important decision you will make.

 This is also true for the "key" you're putting in the
       column family name of nested entities.
1: Design for the questions,
     not the answers.
1: Design for the questions,
           not the answers.

(hat tip to Ilya Katsov from the High Scalability blog
  for this useful way to put it; and possibly to Billy
     Newport or Eben Hewitt for saying it first.)
1: Design for the questions,
     not the answers.
Let's be clear: this sucks big time,
 if you aren't 100% sure what the
     questions are going to be.
Let's be clear: this sucks big time,
 if you aren't 100% sure what the
     questions are going to be.
        Use a relational DB for that!
     Or a document database like CouchDB ...
"But isn't NoSQL more flexible than a
            relational DB?"

        For column schema? Yes!
        For row key structures, NO!
2: There are only two sizes of data:
      too big, and not too big.
2: There are only two sizes of data:
      too big, and not too big.

   (That is, too big to scan all of something
   while answering an interactive request.)
2: There are only two sizes of data:
      too big, and not too big.
3: Be compact.
You can squeeze a lot into a little space.
3: Be compact.
You can squeeze a lot into a little space.
This is also important because the
rowkey and CF name are repeated for
every single value (memory and disk).
File compression can negate this on disk, and prefix
 compression will probably negate this in memory.
4: Use row atomicity as a design tool.
Rows are updated atomically, which gives you a form
          of relational integrity in HBase!
4: Use row atomicity as a design tool.
 If you made this two HBase tables, you couldn't
guarantee integrity (updated to one could succeed,
         while updates to the other fail).
4: Use row atomicity as a design tool.
If you make it one table with a nested entity, you can
  guarantee updates will be atomic, and you can do
       much more complex mutations of state.
5: Attributes can move into the row key
Even if it's not "identifying" (part of the uniqueness of
 an entity), adding an attribute into the row key can
    make access more efficient in some cases.
5: Attributes can move into the row key
Even if it's not "identifying" (part of the uniqueness of
 an entity), adding an attribute into the row key can
    make access more efficient in some cases.
5: Attributes can move into the row key
   This ability to move things left or right (without
changing the physical storage requirements) is part of
          what Lars George calls "folding".

 Also, if you like this subject, go watch his videos on
 advanced HBase schema design, they're awesome.
6: If you nest entities, you can
transactionally pre-aggregate data.
  You can recalculate aggregates on write,
   or periodically with a map/reduce job.
Practically: how do you load schema
             into HBase?
Practically: how do you load schema
             into HBase?
 Direct actuation: https://github.com/larsgeorge/hbase-schema-manager
Practically: how do you load schema
             into HBase?
 Direct actuation: https://github.com/larsgeorge/hbase-schema-manager
     Coming soon: script generation: https://github.com/ivarley/scoot
Thank you!
Questions? @thefutureian

More Related Content

What's hot

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisArnab Mitra
 
Transactional operations in Apache Hive: present and future
Transactional operations in Apache Hive: present and futureTransactional operations in Apache Hive: present and future
Transactional operations in Apache Hive: present and futureDataWorks Summit
 
Multi-Tenant HBase Cluster - HBaseCon2018-final
Multi-Tenant HBase Cluster - HBaseCon2018-finalMulti-Tenant HBase Cluster - HBaseCon2018-final
Multi-Tenant HBase Cluster - HBaseCon2018-finalBiju Nair
 
Introduction to HBase - NoSqlNow2015
Introduction to HBase - NoSqlNow2015Introduction to HBase - NoSqlNow2015
Introduction to HBase - NoSqlNow2015Apekshit Sharma
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars GeorgeJAX London
 
Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012Jay Patel
 
Apache Tez - A New Chapter in Hadoop Data Processing
Apache Tez - A New Chapter in Hadoop Data ProcessingApache Tez - A New Chapter in Hadoop Data Processing
Apache Tez - A New Chapter in Hadoop Data ProcessingDataWorks Summit
 
HBase.pptx
HBase.pptxHBase.pptx
HBase.pptxSadhik7
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbaseiammutex
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...Simplilearn
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceDataWorks Summit
 
Spark Summit EU talk by Mike Percy
Spark Summit EU talk by Mike PercySpark Summit EU talk by Mike Percy
Spark Summit EU talk by Mike PercySpark Summit
 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive QueriesOwen O'Malley
 
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUpon
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUponHBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUpon
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUponCloudera, Inc.
 
Millions of Regions in HBase: Size Matters
Millions of Regions in HBase: Size MattersMillions of Regions in HBase: Size Matters
Millions of Regions in HBase: Size MattersDataWorks Summit
 
Hive + Tez: A Performance Deep Dive
Hive + Tez: A Performance Deep DiveHive + Tez: A Performance Deep Dive
Hive + Tez: A Performance Deep DiveDataWorks Summit
 

What's hot (20)

Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Transactional operations in Apache Hive: present and future
Transactional operations in Apache Hive: present and futureTransactional operations in Apache Hive: present and future
Transactional operations in Apache Hive: present and future
 
Intro to HBase
Intro to HBaseIntro to HBase
Intro to HBase
 
Multi-Tenant HBase Cluster - HBaseCon2018-final
Multi-Tenant HBase Cluster - HBaseCon2018-finalMulti-Tenant HBase Cluster - HBaseCon2018-final
Multi-Tenant HBase Cluster - HBaseCon2018-final
 
Introduction to HBase - NoSqlNow2015
Introduction to HBase - NoSqlNow2015Introduction to HBase - NoSqlNow2015
Introduction to HBase - NoSqlNow2015
 
HBase Advanced - Lars George
HBase Advanced - Lars GeorgeHBase Advanced - Lars George
HBase Advanced - Lars George
 
Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012Cassandra at eBay - Cassandra Summit 2012
Cassandra at eBay - Cassandra Summit 2012
 
Apache Tez - A New Chapter in Hadoop Data Processing
Apache Tez - A New Chapter in Hadoop Data ProcessingApache Tez - A New Chapter in Hadoop Data Processing
Apache Tez - A New Chapter in Hadoop Data Processing
 
HBase.pptx
HBase.pptxHBase.pptx
HBase.pptx
 
Couchdb + Membase = Couchbase
Couchdb + Membase = CouchbaseCouchdb + Membase = Couchbase
Couchdb + Membase = Couchbase
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
 
Internal Hive
Internal HiveInternal Hive
Internal Hive
 
Spark Summit EU talk by Mike Percy
Spark Summit EU talk by Mike PercySpark Summit EU talk by Mike Percy
Spark Summit EU talk by Mike Percy
 
Hive: Loading Data
Hive: Loading DataHive: Loading Data
Hive: Loading Data
 
Optimizing Hive Queries
Optimizing Hive QueriesOptimizing Hive Queries
Optimizing Hive Queries
 
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUpon
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUponHBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUpon
HBaseCon 2012 | Lessons learned from OpenTSDB - Benoit Sigoure, StumbleUpon
 
Millions of Regions in HBase: Size Matters
Millions of Regions in HBase: Size MattersMillions of Regions in HBase: Size Matters
Millions of Regions in HBase: Size Matters
 
Hive + Tez: A Performance Deep Dive
Hive + Tez: A Performance Deep DiveHive + Tez: A Performance Deep Dive
Hive + Tez: A Performance Deep Dive
 

Viewers also liked

Hadoop: Extending your Data Warehouse
Hadoop: Extending your Data WarehouseHadoop: Extending your Data Warehouse
Hadoop: Extending your Data WarehouseCloudera, Inc.
 
Final Year Project report (Jet Engine)
Final Year Project report (Jet Engine)Final Year Project report (Jet Engine)
Final Year Project report (Jet Engine)Pramod Pawar
 
Performance Comparison of Streaming Big Data Platforms
Performance Comparison of Streaming Big Data PlatformsPerformance Comparison of Streaming Big Data Platforms
Performance Comparison of Streaming Big Data PlatformsDataWorks Summit/Hadoop Summit
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryJean-Paul Azar
 
Developing Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaDeveloping Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaJoe Stein
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformJean-Paul Azar
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkRahul Jain
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache KafkaJeff Holoman
 

Viewers also liked (8)

Hadoop: Extending your Data Warehouse
Hadoop: Extending your Data WarehouseHadoop: Extending your Data Warehouse
Hadoop: Extending your Data Warehouse
 
Final Year Project report (Jet Engine)
Final Year Project report (Jet Engine)Final Year Project report (Jet Engine)
Final Year Project report (Jet Engine)
 
Performance Comparison of Streaming Big Data Platforms
Performance Comparison of Streaming Big Data PlatformsPerformance Comparison of Streaming Big Data Platforms
Performance Comparison of Streaming Big Data Platforms
 
Kafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema RegistryKafka and Avro with Confluent Schema Registry
Kafka and Avro with Confluent Schema Registry
 
Developing Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache KafkaDeveloping Real-Time Data Pipelines with Apache Kafka
Developing Real-Time Data Pipelines with Apache Kafka
 
Kafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platformKafka Tutorial - basics of the Kafka streaming platform
Kafka Tutorial - basics of the Kafka streaming platform
 
Real time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache SparkReal time Analytics with Apache Kafka and Apache Spark
Real time Analytics with Apache Kafka and Apache Spark
 
Introduction to Apache Kafka
Introduction to Apache KafkaIntroduction to Apache Kafka
Introduction to Apache Kafka
 

Similar to HBaseCon 2012 | HBase Schema Design - Ian Varley, Salesforce

HBase Schema Design - HBase-Con 2012
HBase Schema Design - HBase-Con 2012HBase Schema Design - HBase-Con 2012
HBase Schema Design - HBase-Con 2012Ian Varley
 
Schemaless Databases
Schemaless DatabasesSchemaless Databases
Schemaless DatabasesDan Gunter
 
Performance By Design
Performance By DesignPerformance By Design
Performance By DesignGuy Harrison
 
Architectural anti-patterns for data handling
Architectural anti-patterns for data handlingArchitectural anti-patterns for data handling
Architectural anti-patterns for data handlingGleicon Moraes
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designphanleson
 
rhbase_tutorial
rhbase_tutorialrhbase_tutorial
rhbase_tutorialAaron Benz
 
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AG
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AGOLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AG
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AGLucidworks
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and UsesSuvradeep Rudra
 
NoSQL and MapReduce
NoSQL and MapReduceNoSQL and MapReduce
NoSQL and MapReduceJ Singh
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesJon Meredith
 
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...IndicThreads
 
Database highload solutions
Database highload solutionsDatabase highload solutions
Database highload solutionslarest
 
Is multi-model the future of NoSQL?
Is multi-model the future of NoSQL?Is multi-model the future of NoSQL?
Is multi-model the future of NoSQL?Max Neunhöffer
 

Similar to HBaseCon 2012 | HBase Schema Design - Ian Varley, Salesforce (20)

HBase Schema Design - HBase-Con 2012
HBase Schema Design - HBase-Con 2012HBase Schema Design - HBase-Con 2012
HBase Schema Design - HBase-Con 2012
 
Schemaless Databases
Schemaless DatabasesSchemaless Databases
Schemaless Databases
 
Performance By Design
Performance By DesignPerformance By Design
Performance By Design
 
Oslo baksia2014
Oslo baksia2014Oslo baksia2014
Oslo baksia2014
 
Architectural anti-patterns for data handling
Architectural anti-patterns for data handlingArchitectural anti-patterns for data handling
Architectural anti-patterns for data handling
 
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table designHBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 04: HBase table design
 
rhbase_tutorial
rhbase_tutorialrhbase_tutorial
rhbase_tutorial
 
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AG
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AGOLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AG
OLAP Battle - SolrCloud vs. HBase: Presented by Dragan Milosevic, Zanox AG
 
NOSQL Databases types and Uses
NOSQL Databases types and UsesNOSQL Databases types and Uses
NOSQL Databases types and Uses
 
NoSQL and MapReduce
NoSQL and MapReduceNoSQL and MapReduce
NoSQL and MapReduce
 
Datastores
DatastoresDatastores
Datastores
 
Uint-5 Big data Frameworks.pdf
Uint-5 Big data Frameworks.pdfUint-5 Big data Frameworks.pdf
Uint-5 Big data Frameworks.pdf
 
Uint-5 Big data Frameworks.pdf
Uint-5 Big data Frameworks.pdfUint-5 Big data Frameworks.pdf
Uint-5 Big data Frameworks.pdf
 
Front Range PHP NoSQL Databases
Front Range PHP NoSQL DatabasesFront Range PHP NoSQL Databases
Front Range PHP NoSQL Databases
 
Nosql seminar
Nosql seminarNosql seminar
Nosql seminar
 
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
Breaking with relational DBMS and dating with Hbase [5th IndicThreads.com Con...
 
NoSQL - Leo's notes
NoSQL - Leo's notesNoSQL - Leo's notes
NoSQL - Leo's notes
 
No sql
No sqlNo sql
No sql
 
Database highload solutions
Database highload solutionsDatabase highload solutions
Database highload solutions
 
Is multi-model the future of NoSQL?
Is multi-model the future of NoSQL?Is multi-model the future of NoSQL?
Is multi-model the future of NoSQL?
 

More from Cloudera, Inc.

Partner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptxPartner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptxCloudera, Inc.
 
Cloudera Data Impact Awards 2021 - Finalists
Cloudera Data Impact Awards 2021 - Finalists Cloudera Data Impact Awards 2021 - Finalists
Cloudera Data Impact Awards 2021 - Finalists Cloudera, Inc.
 
2020 Cloudera Data Impact Awards Finalists
2020 Cloudera Data Impact Awards Finalists2020 Cloudera Data Impact Awards Finalists
2020 Cloudera Data Impact Awards FinalistsCloudera, Inc.
 
Edc event vienna presentation 1 oct 2019
Edc event vienna presentation 1 oct 2019Edc event vienna presentation 1 oct 2019
Edc event vienna presentation 1 oct 2019Cloudera, Inc.
 
Machine Learning with Limited Labeled Data 4/3/19
Machine Learning with Limited Labeled Data 4/3/19Machine Learning with Limited Labeled Data 4/3/19
Machine Learning with Limited Labeled Data 4/3/19Cloudera, Inc.
 
Data Driven With the Cloudera Modern Data Warehouse 3.19.19
Data Driven With the Cloudera Modern Data Warehouse 3.19.19Data Driven With the Cloudera Modern Data Warehouse 3.19.19
Data Driven With the Cloudera Modern Data Warehouse 3.19.19Cloudera, Inc.
 
Introducing Cloudera DataFlow (CDF) 2.13.19
Introducing Cloudera DataFlow (CDF) 2.13.19Introducing Cloudera DataFlow (CDF) 2.13.19
Introducing Cloudera DataFlow (CDF) 2.13.19Cloudera, Inc.
 
Introducing Cloudera Data Science Workbench for HDP 2.12.19
Introducing Cloudera Data Science Workbench for HDP 2.12.19Introducing Cloudera Data Science Workbench for HDP 2.12.19
Introducing Cloudera Data Science Workbench for HDP 2.12.19Cloudera, Inc.
 
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19Cloudera, Inc.
 
Leveraging the cloud for analytics and machine learning 1.29.19
Leveraging the cloud for analytics and machine learning 1.29.19Leveraging the cloud for analytics and machine learning 1.29.19
Leveraging the cloud for analytics and machine learning 1.29.19Cloudera, Inc.
 
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19Cloudera, Inc.
 
Leveraging the Cloud for Big Data Analytics 12.11.18
Leveraging the Cloud for Big Data Analytics 12.11.18Leveraging the Cloud for Big Data Analytics 12.11.18
Leveraging the Cloud for Big Data Analytics 12.11.18Cloudera, Inc.
 
Modern Data Warehouse Fundamentals Part 3
Modern Data Warehouse Fundamentals Part 3Modern Data Warehouse Fundamentals Part 3
Modern Data Warehouse Fundamentals Part 3Cloudera, Inc.
 
Modern Data Warehouse Fundamentals Part 2
Modern Data Warehouse Fundamentals Part 2Modern Data Warehouse Fundamentals Part 2
Modern Data Warehouse Fundamentals Part 2Cloudera, Inc.
 
Modern Data Warehouse Fundamentals Part 1
Modern Data Warehouse Fundamentals Part 1Modern Data Warehouse Fundamentals Part 1
Modern Data Warehouse Fundamentals Part 1Cloudera, Inc.
 
Extending Cloudera SDX beyond the Platform
Extending Cloudera SDX beyond the PlatformExtending Cloudera SDX beyond the Platform
Extending Cloudera SDX beyond the PlatformCloudera, Inc.
 
Federated Learning: ML with Privacy on the Edge 11.15.18
Federated Learning: ML with Privacy on the Edge 11.15.18Federated Learning: ML with Privacy on the Edge 11.15.18
Federated Learning: ML with Privacy on the Edge 11.15.18Cloudera, Inc.
 
Analyst Webinar: Doing a 180 on Customer 360
Analyst Webinar: Doing a 180 on Customer 360Analyst Webinar: Doing a 180 on Customer 360
Analyst Webinar: Doing a 180 on Customer 360Cloudera, Inc.
 
Build a modern platform for anti-money laundering 9.19.18
Build a modern platform for anti-money laundering 9.19.18Build a modern platform for anti-money laundering 9.19.18
Build a modern platform for anti-money laundering 9.19.18Cloudera, Inc.
 
Introducing the data science sandbox as a service 8.30.18
Introducing the data science sandbox as a service 8.30.18Introducing the data science sandbox as a service 8.30.18
Introducing the data science sandbox as a service 8.30.18Cloudera, Inc.
 

More from Cloudera, Inc. (20)

Partner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptxPartner Briefing_January 25 (FINAL).pptx
Partner Briefing_January 25 (FINAL).pptx
 
Cloudera Data Impact Awards 2021 - Finalists
Cloudera Data Impact Awards 2021 - Finalists Cloudera Data Impact Awards 2021 - Finalists
Cloudera Data Impact Awards 2021 - Finalists
 
2020 Cloudera Data Impact Awards Finalists
2020 Cloudera Data Impact Awards Finalists2020 Cloudera Data Impact Awards Finalists
2020 Cloudera Data Impact Awards Finalists
 
Edc event vienna presentation 1 oct 2019
Edc event vienna presentation 1 oct 2019Edc event vienna presentation 1 oct 2019
Edc event vienna presentation 1 oct 2019
 
Machine Learning with Limited Labeled Data 4/3/19
Machine Learning with Limited Labeled Data 4/3/19Machine Learning with Limited Labeled Data 4/3/19
Machine Learning with Limited Labeled Data 4/3/19
 
Data Driven With the Cloudera Modern Data Warehouse 3.19.19
Data Driven With the Cloudera Modern Data Warehouse 3.19.19Data Driven With the Cloudera Modern Data Warehouse 3.19.19
Data Driven With the Cloudera Modern Data Warehouse 3.19.19
 
Introducing Cloudera DataFlow (CDF) 2.13.19
Introducing Cloudera DataFlow (CDF) 2.13.19Introducing Cloudera DataFlow (CDF) 2.13.19
Introducing Cloudera DataFlow (CDF) 2.13.19
 
Introducing Cloudera Data Science Workbench for HDP 2.12.19
Introducing Cloudera Data Science Workbench for HDP 2.12.19Introducing Cloudera Data Science Workbench for HDP 2.12.19
Introducing Cloudera Data Science Workbench for HDP 2.12.19
 
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19
Shortening the Sales Cycle with a Modern Data Warehouse 1.30.19
 
Leveraging the cloud for analytics and machine learning 1.29.19
Leveraging the cloud for analytics and machine learning 1.29.19Leveraging the cloud for analytics and machine learning 1.29.19
Leveraging the cloud for analytics and machine learning 1.29.19
 
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19
Modernizing the Legacy Data Warehouse – What, Why, and How 1.23.19
 
Leveraging the Cloud for Big Data Analytics 12.11.18
Leveraging the Cloud for Big Data Analytics 12.11.18Leveraging the Cloud for Big Data Analytics 12.11.18
Leveraging the Cloud for Big Data Analytics 12.11.18
 
Modern Data Warehouse Fundamentals Part 3
Modern Data Warehouse Fundamentals Part 3Modern Data Warehouse Fundamentals Part 3
Modern Data Warehouse Fundamentals Part 3
 
Modern Data Warehouse Fundamentals Part 2
Modern Data Warehouse Fundamentals Part 2Modern Data Warehouse Fundamentals Part 2
Modern Data Warehouse Fundamentals Part 2
 
Modern Data Warehouse Fundamentals Part 1
Modern Data Warehouse Fundamentals Part 1Modern Data Warehouse Fundamentals Part 1
Modern Data Warehouse Fundamentals Part 1
 
Extending Cloudera SDX beyond the Platform
Extending Cloudera SDX beyond the PlatformExtending Cloudera SDX beyond the Platform
Extending Cloudera SDX beyond the Platform
 
Federated Learning: ML with Privacy on the Edge 11.15.18
Federated Learning: ML with Privacy on the Edge 11.15.18Federated Learning: ML with Privacy on the Edge 11.15.18
Federated Learning: ML with Privacy on the Edge 11.15.18
 
Analyst Webinar: Doing a 180 on Customer 360
Analyst Webinar: Doing a 180 on Customer 360Analyst Webinar: Doing a 180 on Customer 360
Analyst Webinar: Doing a 180 on Customer 360
 
Build a modern platform for anti-money laundering 9.19.18
Build a modern platform for anti-money laundering 9.19.18Build a modern platform for anti-money laundering 9.19.18
Build a modern platform for anti-money laundering 9.19.18
 
Introducing the data science sandbox as a service 8.30.18
Introducing the data science sandbox as a service 8.30.18Introducing the data science sandbox as a service 8.30.18
Introducing the data science sandbox as a service 8.30.18
 

Recently uploaded

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 

Recently uploaded (20)

Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 

HBaseCon 2012 | HBase Schema Design - Ian Varley, Salesforce

  • 2. HBase Schema Design How I Learned To Stop Worrying And Love Denormalization
  • 3. What Is Schema Design?
  • 4. Who am I? Ian Varley Software engineer at Salesforce.com @thefutureian
  • 5. What Is Schema Design? Logical Data Modeling
  • 6. What Is Schema Design? Logical Data Modeling + Physical Implementation
  • 7. You always start with a logical model. Even if it's just an implicit one. That's totally fine. (If you're right.)
  • 8. There are lots of ways to model data. The most common one is: Entity / Attribute / Relationship (This is probably what you know of as just "data modeling".)
  • 9. There's a well established visual language for data modeling.
  • 10. Entities are boxes. With rounded corners if you're fancy.
  • 11. Attributes are listed vertically in the box. Optionally with data types, for clarity.
  • 12. Relationships are connecting lines. Optionally with special endpoints, and/or verbs
  • 15. Example: Concerts A note about diagrams: they're useful for communicating, but can be more trouble than they're worth. Don't do them out of obligation; only do them to understand your problem better.
  • 17. For relational databases, you usually start with this normalized model, then plug & chug.
  • 18. For relational databases, you usually start with this normalized model, then plug & chug. Entities → Tables Attributes → Columns Relationships → Foreign Keys Many-to-many → Junction tables Natural keys → Artificial IDs
  • 19.
  • 21. So, what's missing? If your data is not massive, NOTHING. You should use a relational database. They rock*
  • 22. So, what's missing? If your data is not massive, NOTHING. You should use a relational database. They rock* * - This statement has not been approved by the HBase product management committee, and neglects known deficiencies with the relational model such as poor modeling of hierarchies and graphs, overly rigid attribute structure enforcement, neglect of the time dimension, and physical optimization concerns leaking into the conceptual abstraction.
  • 23. Relational DBs work well because they are close to the pure logical model. That model is less likely to change as your business needs change. You may want to ask different questions over time, but if you got the logical model correct, you'll have the answers.
  • 24. Ah, but what if you do have massive data? Then what's missing?
  • 25. Problem: The relational model doesn't acknowledge scale.
  • 26. Problem: The relational model doesn't acknowledge scale. "It's an implementation concern; you shouldn't have to worry about it."
  • 27. The trouble is, you do have to worry about it. So you... ● Add indexes ● Add hints ● Write really complex, messy SQL ● Memorize books by Tom Kyte & Joe Celko ● Bow down to the optimizer! ● Denormalize ● Cache ● etc ...
  • 28. Generally speaking, you poke holes in the abstraction, and it starts leaking.
  • 29. So then you hear about this thing called NoSQL. Can it help?
  • 30. Maybe. But ultimately, it's just a different way of physically representing your same logical data model. Some things are easier; some are much harder. If you haven't started by understanding your logical model, you're doing it wrong.
  • 31. HBase Architecture: A Brief Recap
  • 32. HBase Architecture: A Brief Recap • Scales by splitting all rows into regions
  • 33. HBase Architecture: A Brief Recap • Scales by splitting all rows into regions • Each region is hosted by exactly one server
  • 34. HBase Architecture: A Brief Recap • Scales by splitting all rows into regions • Each region is hosted by exactly one server • Writes are held (sorted) in memory until flush
  • 35. HBase Architecture: A Brief Recap • Scales by splitting all rows into regions • Each region is hosted by exactly one server • Writes are held (sorted) in memory until flush • Reads merge rows in memory with flushed files
  • 36. HBase Architecture: A Brief Recap • Scales by splitting all rows into regions • Each region is hosted by exactly one server • Writes are held (sorted) in memory until flush • Reads merge rows in memory with flushed files • Reads & writes to a single row are consistent
  • 37. So what does data in HBase look like?
  • 38. HBase Data Model: Brief Recap
  • 39. HBase Data Model: Brief Recap Table: design-time namespace, has many rows.
  • 40. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic byte array, with one row key
  • 41. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic byte array, with one row key Not just a bunch of bytes, dude! A k/v map!
  • 42. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key
  • 43. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row
  • 44. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Value: a value in the k/v container inside a row
  • 45. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Value: a value in the k/v container inside a row
  • 46. HBase Data Model: Brief Recap Hold up! What about Table: design-time namespace, has many rows. time? Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Value: a value in the k/v container inside a row
  • 47. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 48. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 49. The "row" is atomic, and gets flushed to disk periodically. But it doesn't have to be flushed into just a single file! HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 50. This "row" brokenatomic, and gets store It can be guy is up into different flushed to disk periodically. Butand files with different properties, it doesn't have to caninto just just a subset. reads be look at one file. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 51. This "row" brokenatomic, and gets store can is guy is up into Families". It This becalled "Column different It's flushed to disk periodically. want, and files inof an advancedyou Butoption, so whatever way design it doesn't kind be have to caninto just one file.at a subset. reads think too much about it yet. don't choose to look HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 52. This "row" brokenatomic, and gets store can is guy is up into Families". It This becalled "Column different It's flushed to disk periodically. want, and allows whatever performance Butoption, so it doesn't From the Percolator way by Google: "Bigtable paper files inof an advancedyou characteristics of the have to caninto the one design subset. kind becontrol just users to file. reads by grouping amuch about a yet. choose to columns into a locality look at it don't think too set of to think about CFs. table group." That's a good way HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 53. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 54. Calling these "columns" is an unfortunate use of terminology. They're not fixed; each row can have different keys, and the names are not defined at runtime. So you can represent another axis of data (in the key of the key/value pair). More on that later. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 55. They're officially called "column qualifiers". But many people just say "columns". Or "CQ". Or "Quallie". Now you're one of the cool kids. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 56. What data types are stored in key/value pairs? HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 57. What data types are stored in key/value pairs? It's all bytes. HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 58. What data types are stored in key/value pairs? Row keys, column names, values: arbitrary bytes HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 59. What data types are stored in key/value pairs? Row keys, column names, values: arbitrary bytes Table and column family names: printable characters HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 60. What data types are stored in key/value pairs? Row keys, column names, values: arbitrary bytes Table and column family names: printable characters Timestamps: long integers HBase Data Model: Brief Recap Table: design-time namespace, has many rows. Row: atomic key/value container, with one row key Column Family: divide columns into physical files Column: a key in the k/v container inside a row Timestamp: long milliseconds, sorted descending Value: a time-versioned value in the k/v container
  • 61. HBase Data Model: Brief Recap One more thing that bears repeating: every "cell" (i.e. the time-versioned value of one column in one row) is stored "fully qualified" (with its full rowkey, column family, column name, etc.) on disk.
  • 62. So now you know what's available. Now, how do you model things?
  • 63. Let's start with the entity / attribute / relationship modeling paradigm, and see how far we get applying it to HBase.
  • 64. A note about my example: it's for clarity, not realism. For bands & shows, there's not enough data to warrant using HBase, even if you're tracking every show by every band for all of human history. It might be GB, but not TB.
  • 65. So, back to entities (boxes). With fancy rounded corners.
  • 66. What's that in HBase? A table, right?
  • 67. What's that in HBase? A table, right? Dramatic foreshadowing: not always ...
  • 68. And what do entities have?
  • 70. Attributes! For example: a "Band" entity might have a "Name" (with values like "Jonathan Coulton") and a "Genre" (with values like "Nerd Core")
  • 71. Logically, attributes are unordered. Their vertical position is meaningless. They're simply characteristics of the entity.
  • 72. Attributes can be identifying. i.e. they uniquely identify a particular instance of that entity.
  • 73. Attributes can be identifying. i.e. they uniquely identify a particular instance of that entity. Logical models usually leave this out, and identity is implied (i.e. we just assume there's some set of attributes that's identifying, but we don't have to say what it is)
  • 74. Attributes can be identifying. i.e. they uniquely identify a particular instance of that entity. PK Physical models refer to it explicitly, like how in a relational database model you'd label some set of attributes as being the "Primary Key" (PK).
  • 75. Attributes can be identifying. i.e. they uniquely identify a particular instance of that entity. So in our Band example, neither Name nor Genre is uniquely identifying, but something like URL might be.
  • 76. How does this map to HBase?
  • 77. How does this map to HBase? Identifying attributes (aka the "PK") become parts of the row key, and other attributes become columns.
  • 78. So here's a Band schema. The row key is the URL, and we have Name and Genre as attributes.
  • 79. A much common pattern is to use IDs. That way, you have an immutable way to refer to this entity forever, even if they leave MySpace.
  • 80. A much common pattern is to use IDs. That way, you have an immutable way to refer to this entity forever, even if they leave MySpace. Where do IDs come from? We'll talk about that later.
  • 81. If there's just a single row key, how can there be multiple identifying attributes?
  • 82. Let's call that "mashing". Which is to say, concatenation, in either a fixed-width or delimited manner, in the byte array.
  • 83. Mashing includes several techniques: ● Fixed byte width representation ● Delimiting (for variable length) ● Other serialization (avro, etc.)
  • 84. Mashing includes several techniques: ● Fixed byte width representation ● Delimiting (for variable length) ● Other serialization (avro, etc.) Doesn't matter how you do it; the important thing is that any byte array in HBase can represent more than one logical attribute.
  • 85. If we want, we can even add types to the schema definition.
  • 86. If we want, we can even add types to the schema definition. ?
  • 87. If we want, we can even add types to the schema definition. ? HBase don't care, but we do (sometimes).
  • 88. If we want, we can even add types. You could also mark things as ASC or DESC, depending on whether you invert the bits. ?
  • 89. This is pretty textbook stuff, but here's where it gets exciting.
  • 90. This is pretty textbook stuff, but here's where it gets exciting. (If you're astute, you'll notice we haven't talked about relationships yet.)
  • 91. HBase has no foreign keys, or joins, or cross-table transactions. This can make representing relationships between entities ... tricky.
  • 92. Part of the beauty of the relational model is that you can punt on this question. If you model the entities as fully normalized, then you can write any query you want at run time, and the DB performs joins on tables as optimally as it can. (This relies heavily on indexing.)
  • 93. In HBase (or any distributed DB) you don't have that luxury. Joins get way more expensive and complicated across a distributed cluster of machines, as do the indexes that make them happen efficiently. HBase has neither joins nor indexes.
  • 94. You have two choices, if you need relationships between entities.
  • 95. You have two choices, if you need relationships between entities. ● Roll your own joins
  • 96. You have two choices, if you need relationships between entities. ● Roll your own joins ● Denormalize the data
  • 97. Rolling your own joins is hard. You'll probably get it wrong if you try to do it casually. Ever implemented a multi-way merge sort by hand?
  • 98. Denormalizing is fun! But it also sucks. We'll see why.
  • 99. The basic concept of denormalization is simple: two logical entities share one physical representation.
  • 100. The basic concept of denormalization is simple: two logical entities share one physical representation. Of course, there are lots of ways to skin a cat...
  • 101. Let's look at standard relational database denormalization techniques first.
  • 102. In a relational database, if the normalized physical model is this:
  • 103. You could start with the Band, and give it extra columns to hold the shows:
  • 104. You could start with the Band, and give it extra columns to hold the shows:
  • 105. That's pretty obviously a bad idea, because bands can play a lot of shows. WTF?
  • 106. You could also just give it an unstructured blob of text for all the shows.
  • 107. You could also just give it an unstructured blob of text for all the shows. But then you've given up the integrity of your data. (Which might be fine. If so, stop here.)
  • 108. You get similar problems if you try to bring all the info into the Show table.
  • 109. Another solution is to focus on the junction table.
  • 110. And pull in copies of the info in the other tables:
  • 111. Leaving you with one table, with one row per band/show combination:
  • 112. The cons to this should be self-evident. Updating and querying are more complicated, because you have to deal with many representations of the "same" data, which could get out of sync, etc.
  • 113. But the pros are that with huge data, answering some questions is much faster. (If you happen to be asking the query in the same way you structured the denormalization, that is.)
  • 114. So back to HBase. How do you denormalize in an HBase schema?
  • 115. HBase columns can be defined at runtime. A column doesn't have to represent a pre-defined attribute.
  • 116. HBase columns can be defined at runtime. A column doesn't have to represent a pre-defined attribute. In fact, it doesn't have to be an attribute at all.
  • 117. A set of dynamically named columns can represent another entity!
  • 118.
  • 119. If you put data into the column name, and expect many such columns in the same row, then logically, you've created a nested entity.
  • 120. You can scan over columns. See: hadoop-hbase.blogspot.com/2012/01/hbase-intra-row-scanning.html
  • 121. So we can store shows inside bands. Which is like the denormalization we say earlier, except without the relational DB kludges.
  • 122. Note! HBase don't care. It's just a matter of how your app treats the columns. If you put repeating info in column names, you're doing this.
  • 123. Why is this so difficult for most relational database devs to grok? Because relational databases have no concept of nested entities! You'd make it a separate table in an RDBMS, which is more flexible but much more difficult to optimize.
  • 124. It's very difficult to talk about HBase schemas if you don't acknowledge this. You don't have to represent it this way (with a nested box) but you have to at least acknowledge it. And maybe name it.
  • 125. But, once you do acknowledge it, you can do some neat things.
  • 126. Nested entities can have attributes, some of which are identifying.
  • 127. Nested entities can have attributes, some of which are identifying. Identifying attributes make up the column qualifier (just like row keys, it could be multiple attributes mashed together)
  • 128. Nested entities can have attributes, some of which are identifying. Identifying attributes Non-identifying make up the column attributes are held qualifier (just like in the value (again, row keys, it could be you could mash multiple attributes many attributes in mashed together) here)
  • 129. Shows is nested in Band show_id is the column qualifier Other attributes are mashed into the value Everything else The column qualifier gets mashed into is the show id. the value field.
  • 130. 1 table can have many nested entities, provided your app can tell them apart.
  • 131. How do you tell them apart? With prefixes ... qualifier starts with: "s" + show_id "a" + album_id "m" + name
  • 132. Where can you nest entities? Knock yourself out.
  • 133. Where can you nest entities? Knock yourself out. ● In columns
  • 134. Where can you nest entities? Knock yourself out. ● In columns ● Two levels deep in columns!
  • 135. Where can you nest entities? Knock yourself out. ● In columns ● Two levels deep in columns! ● In the row key?!
  • 136. Where can you nest entities? Knock yourself out. ● In columns ● Two levels deep in columns! ● In the row key?! ● Using timestamps as a dimension!!
  • 137. This is a fundamental modeling property of HBase: nesting entities.
  • 138. Wait, what about Column Families?
  • 139. They're just namespaces--additional vertical sections on the same entity.
  • 140. Where column families aren't shown explicitly, let's assume there's just one.
  • 141. So that brings us to a standard way to show an HBase schema: Table: Top level entity name, fixed at design time. Row key: Can consist of multiple parts, each with a name & type. All data in one row shares the same row key. Can be nested. Column family: A container that allows sets of columns to have separate storage & semantics. Column qualifiers: Fixed attributes--design-time named columns, holding a value of a certain type. Nested entities: Run-time named column qualifiers, where the qualifier is made up of one (or more) values, each with a type, along with one or more values (by timestamp) which also have a type. Nested versions: Because multiple timestamped copies of each value can exist, you can also treat the timestamp as a modeled dimension in its own right. Hell, you could even use a long that's not a timestamp (like, say, an ID number). Caveats apply.
  • 142. "But," you say, "what if I don't have all of these fancy modeling tools?"
  • 143. Say it in text. XML, JSON, DML, whatever you like. <table name="Band"> <key> <column name="band_id" type="int" /> </key> <columnFamily name="cf1"> <column name="band_name" type="string"/> <column name="hometown" type="string"/> <entity name="Show"> <key> <column name="show_id"> </key> <column name="date" type="date" /> </entity> </columnFamily> </table>
  • 144. Text is faster and more general, but slightly harder to grok quickly. So we'll stick with diagrams here.
  • 145. Some examples are in order.
  • 146. Example 1: a simple parent/child relationship Relational Schema: Applicants & Answers Standard parent/child relationship. One Applicant has many Answers; every Answer relates to a single Applicant (by id). It also relates to a Question (not shown). SQL would have you JOIN them to materialize an applicant and their answers.
  • 147. HBase Schema: Answers By Applicant ● Answer is contained implicitly in Applicant ● If you know an applicant_id, you get O(1) access ● If you know an applicant_id AND question_id, O(1) access ● Answer.created_date is implicit in the timestamp on value
  • 148. HBase Schema: Answers By Applicant ● You get answer history for free ● Applicant.applied_date can be implicit in the timestamp ● More attributes on applicant directly? Just add them! ● Answers are atomic and transactional by Applicant!!
  • 149. Example of rows in HBase:
  • 150. Before you get too excited, remember that there are cons to denormalization.
  • 151. The cons: ● Nested entities aren't independent any more. ○ No: "SELECT avg(value) FROM Answer WHERE question_id = 123;" ○ But you can still do that with map/reduce ● This decomposition only works in one direction. ○ No relation chains without serious trickery. ○ Timestamps are another dimension, but that counts as trickery. ● No way to enforce the foreign key to another table. ○ But would you really do that in a big RDBMS? ● On disk, it repeats the row key for every column ○ You didn't really save anything by having applicant_id be implied. ○ Or did you? Compression negates that on disk ... ○ ... and prefix compression (HBASE-4218) will totally sink this.
  • 152. Example 2: dropping some database science Relational Schema: Users And Messages Many-to-many relationship. One User sees many Messages, and a single Message can be seen by many Users. We want to do things like show the most recent message by subject (e.g. an inbox view).
  • 153. What kind of SQL would you run on this? Say, we want to get the most recent 20 messages for 1 user. SELECT TOP 20 M.subject, M.body FROM User_Message UM INNER JOIN Message M ON UM.message_id = M.message_id WHERE UM.user_id = <user_id> ORDER BY M.sent_date DESC
  • 154. Seems easy, right? Well, the database is doing some stuff behind the scenes for you: Assuming no secondary indexes, it might: ● Drive the join from the User_Message table ● For each new record with our given user_id, do a single disk access into the Message table (i.e. a hash_join) ● Get the records for *every* message for this user ● Sort them all ● Take the top 20 No shortcuts; we can't find the top 20 by date w/o seeing ALL messages. This gets more expensive as a user gets more messages. (But it's still pretty fast if a given user has a reasonable number of messages).
  • 155. How could you do this in HBase? Try the same pattern as parent / child? 1. Because of the many-to-many, you now have N copies of the message (one per user). ○ Maybe that's OK (especially if it's immutable!). Disk is cheap. 2. Your statement has to do the same amount of work, but now you have to do it yourself. :(
  • 156. If I know that I always want it ordered by date, why not store it that way? ● Now I can scan over messages by date until I get enough; it's O(1) ● But what if I want it by message_id again? Doh. I'm screwed, unless ...
  • 157. I store it both ways! Nice: updates to this are transactional (consistent) for a given user, because it's all in one row. So it's not a bear to maintain.
  • 158. Which I could even do in different column families ... (Makes sense if I don't usually access them at the same time; I only pay the cost for the query I am running.)
  • 160. Or I could just use the by-date one as an "index" ... So I only store the subject and body once. This means I need to perform my own "join" in code.
  • 161. See a theme emerging? Relational DBs lull you into not thinking about physical access as much; but when you have to scale, there are hard limits. HBase makes you think about it sooner, but gives you the tools to think about it in more a straightforward way.
  • 162. Example 3: Flurry See: http://www.flurry.com/data/ ● One row per device ● Nested entity in CF "Sessions" ○ Polymorphic "fragments" of session reports ○ Map/Reduce transforms Caveat: this is based on email exchanges, so the details may be wonky, but I think the overall point is right.
  • 163. Example 4: Indexes Example from Andrew Purtell ● Using one table as an index into another often makes sense ● Can't be transactional (without external coordination) ● So you have to keep it clean, or tolerate dirty indexes ● Note that there are several attempts to add solid general purpose indexing to HBase, but so far none have caught on. Same caveat: this is based on email exchanges, so the details may be wonky, but I think the overall point is right.
  • 164. Here are some more design patterns.
  • 165. 0: The row key design is the single most important decision you will make.
  • 166. 0: The row key design is the single most important decision you will make. This is also true for the "key" you're putting in the column family name of nested entities.
  • 167. 1: Design for the questions, not the answers.
  • 168. 1: Design for the questions, not the answers. (hat tip to Ilya Katsov from the High Scalability blog for this useful way to put it; and possibly to Billy Newport or Eben Hewitt for saying it first.)
  • 169. 1: Design for the questions, not the answers.
  • 170. Let's be clear: this sucks big time, if you aren't 100% sure what the questions are going to be.
  • 171. Let's be clear: this sucks big time, if you aren't 100% sure what the questions are going to be. Use a relational DB for that! Or a document database like CouchDB ...
  • 172. "But isn't NoSQL more flexible than a relational DB?" For column schema? Yes! For row key structures, NO!
  • 173. 2: There are only two sizes of data: too big, and not too big.
  • 174. 2: There are only two sizes of data: too big, and not too big. (That is, too big to scan all of something while answering an interactive request.)
  • 175. 2: There are only two sizes of data: too big, and not too big.
  • 176. 3: Be compact. You can squeeze a lot into a little space.
  • 177. 3: Be compact. You can squeeze a lot into a little space.
  • 178. This is also important because the rowkey and CF name are repeated for every single value (memory and disk). File compression can negate this on disk, and prefix compression will probably negate this in memory.
  • 179. 4: Use row atomicity as a design tool. Rows are updated atomically, which gives you a form of relational integrity in HBase!
  • 180. 4: Use row atomicity as a design tool. If you made this two HBase tables, you couldn't guarantee integrity (updated to one could succeed, while updates to the other fail).
  • 181. 4: Use row atomicity as a design tool. If you make it one table with a nested entity, you can guarantee updates will be atomic, and you can do much more complex mutations of state.
  • 182. 5: Attributes can move into the row key Even if it's not "identifying" (part of the uniqueness of an entity), adding an attribute into the row key can make access more efficient in some cases.
  • 183. 5: Attributes can move into the row key Even if it's not "identifying" (part of the uniqueness of an entity), adding an attribute into the row key can make access more efficient in some cases.
  • 184. 5: Attributes can move into the row key This ability to move things left or right (without changing the physical storage requirements) is part of what Lars George calls "folding". Also, if you like this subject, go watch his videos on advanced HBase schema design, they're awesome.
  • 185. 6: If you nest entities, you can transactionally pre-aggregate data. You can recalculate aggregates on write, or periodically with a map/reduce job.
  • 186. Practically: how do you load schema into HBase?
  • 187. Practically: how do you load schema into HBase? Direct actuation: https://github.com/larsgeorge/hbase-schema-manager
  • 188. Practically: how do you load schema into HBase? Direct actuation: https://github.com/larsgeorge/hbase-schema-manager Coming soon: script generation: https://github.com/ivarley/scoot