Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 36 ยท Getting Started

What Is Apache HBase?

Learn what Apache HBase is, the problems it solves, how it stores huge sorted tables across many servers, and when it is the right database to choose.

Imagine a table with ten billion rows. New rows arrive thousands of times per second, and your application must read any single row in a few milliseconds. A single database server cannot hold that table, and a traditional relational database starts to struggle long before you reach that size. Apache HBase is a database built for exactly this situation.

HBase is an open-source, distributed, sorted, column-family-oriented store. It runs on top of the Hadoop Distributed File System (HDFS) and was modeled on Google's Bigtable paper. In this lesson you learn what that description means, what HBase is good at, and what it is bad at, so that you can decide quickly whether a project needs it.

How this course works. The site cannot run an HBase cluster in your browser. Real HBase shell commands and Java code are shown as read-only listings, and every output is shown only when we are certain of it. Next to them you get small, clearly labelled Java stand-ins that you can run: they re-create the ideas (sorted keys, versions, regions, the write path) in plain Java, so you understand why HBase behaves the way it does.

The big idea in one sentence

HBase stores data as one gigantic sorted map: a row key leads to columns, and each column holds a value (with a timestamp). Because the map is sorted by row key, it can be cut into contiguous ranges, and each range can live on a different server. That single design choice gives you scale-out storage and fast lookups by key.

What HBase gives you

Scales out Add servers, get more storage and throughput
Fast key lookups Single-row reads and writes in milliseconds
Sparse tables Empty cells cost nothing
Versions Every cell can keep several timestamped values

One sorted table, split into many ranges.

1 / 2

A sorted map, not a spreadsheet

Many people picture an HBase table as a spreadsheet with a few rows. A better picture is a nested sorted map. Roughly:

TEXT
table  ->  row key  ->  column family : qualifier  ->  timestamp  ->  value

Rows are kept in byte-wise lexicographic order of the row key. Inside a row, columns are grouped into column families (declared when you create the table) and each column inside a family has a qualifier you can invent at any time. Every cell remembers more than one version of its value, newest first.

The next example is a stand-in written in plain Java (it is not HBase code). A TreeMap plays the role of the table: it keeps keys sorted, and a range scan is just a view of the keys between a start and an end.

Java Stand-in: a table is a sorted map

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Notice two things. The rows come out sorted even though we inserted them out of order. And user#001 has a city column while user#002 does not: nothing is stored for a missing column. That is what sparse means.

Where HBase sits in the Hadoop world

HBase does not manage disks itself. It stores its files in HDFS, which replicates every block (three copies by default), so a dead disk or machine loses nothing. It uses Apache ZooKeeper to elect a leader and to track which servers are alive. You will meet both in HBase and the Hadoop Ecosystem.

Unlike a batch system such as MapReduce, HBase answers random, real-time reads and writes. You can read one row out of billions in milliseconds. This combination (huge storage on cheap machines plus low-latency access) is why companies used HBase for messaging inboxes, time-series metrics, user profiles and search-index metadata.

Strengths

  • Linear scale-out. Double the servers and you roughly double capacity and throughput.
  • Strong consistency per row. A read of a row always sees the latest committed write to that row. Many NoSQL stores give you eventual consistency instead.
  • Automatic sharding. Tables split into regions automatically as they grow. You do not shard by hand.
  • Write-friendly. Writes go to memory and a log first, so they are fast even on spinning disks.
  • Versioning and TTL. Cells keep several timestamped versions, and old data can expire by itself.
  • Hadoop integration. MapReduce and Spark can read and write HBase tables directly.

Weaknesses

  • Only the row key is indexed. If you search by anything else, HBase must scan. Good design means choosing the row key around your questions (the Schema Design chapter of the HBase track covers this).
  • No joins and no multi-table transactions. Atomicity is per row.
  • Operational weight. A real cluster needs HDFS, ZooKeeper, a Master and several RegionServers. For a few gigabytes of data this is far too much machinery.
  • Not for ad-hoc analytics. Scanning an entire large table for a report is slow compared with a columnar warehouse.

When should you pick HBase?

HBase is a good fit when most of these are true:

  1. You have hundreds of millions of rows or more, or you expect to.
  2. You usually access data by a known key or a key range (a user, a device and a time window).
  3. Write volume is high and steady.
  4. You already run Hadoop or are happy to run it.

It is a poor fit when your data fits on one machine, when you need joins and flexible queries, or when you need multi-row transactions. Use PostgreSQL, MySQL or similar there; see HBase vs RDBMS and Other NoSQL Stores.

A first look at real HBase

Here is what working with HBase looks like in its shell. These lines are read-only; later chapters explain each one.

Terminal
create 'users', 'info'
put 'users', 'user#001', 'info:name', 'Jon'
get 'users', 'user#001'
scan 'users', {STARTROW => 'user#001', LIMIT => 10}

And a second stand-in: HBase reads scan forward from a start row, so "the next ten users after this one" is cheap. This Java stand-in implements paging with a start key, the same pattern a real scan uses.

Java Stand-in: paging with a start row

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with IO.readln() or a Scanner), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which description best fits the HBase data model?

    HBase tables are sorted by row key and hold column families of versioned cells. That ordering is what lets a table be split into ranges across servers.
  2. 2. Where does HBase store its data files?

    HBase persists HFiles and its write-ahead logs in HDFS. ZooKeeper only holds small coordination data.
  3. 3. A query asks for all users in a given city, but city is not part of the row key. What will HBase do by default?

    Only the row key is indexed. Any other predicate means scanning (with a filter), so you design row keys around your main access pattern.
  4. 4. Which workload is a poor fit for HBase?

    Small data with relational queries is better served by a relational database. HBase shines at huge key-based workloads.

Summary

  • HBase is a distributed, sorted, column-family database built on HDFS and inspired by Google Bigtable.
  • Data is a sorted map: row key, column family and qualifier, timestamp, value.
  • It gives linear scale-out, per-row strong consistency, automatic sharding and fast key lookups.
  • It has no joins, no secondary indexes and no multi-row transactions; the row key is your index.
  • Choose it for huge, key-oriented, write-heavy data, not for small relational workloads.

Next: HBase vs RDBMS and Other NoSQL Stores