Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

HBase Practice and Interview Questions

Practice HBase design with exercises on row keys, hotspots and versions, plus common interview questions with short answers and runnable Java checkers.

You have now seen the design rules, the tuning levers and two worked projects. This lesson is practice: three exercises you can run, then the questions that come up most often in HBase interviews and design reviews, each with a short, reasoned answer. Try to answer before reading.

HBase cannot run in the live editors. The exercises use small Java stand-ins (sorted maps and simple models) so you can check your reasoning. Nothing here needs a cluster.

Exercise 1: spot the hotspot

A table is pre-split into 4 regions at the keys "4", "8" and "c". Three candidate row-key schemes are proposed. Run the program, then decide which schemes are safe and why. Then change the schemes and test your own.

Java Which key scheme hotspots? (stand-in)

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.

Scheme A puts everything in one region. B and C spread. D is the subtle one: a low-cardinality first field with a skewed distribution. Only two distinct prefixes exist (us for about 80% of the rows, de for 20%), and both happen to sort into the last region here, so one server takes everything. A skewed or low-cardinality prefix is as bad as a monotonic one.

Exercise 2: reverse the scan

Requirement: "Show the latest 3 login events of a user." Starting from key userId|loginTimestamp, you must change the key. Complete the exercise in the editor: change key() so that a scan from the user's prefix returns newest first, then check that the three results are 5, 4 and 3.

Java Newest three logins

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.

The fix is Long.MAX_VALUE - ts instead of ts in the key (the width stays 19 digits).

Exercise 3: versions and the max-timestamp trap

A client writes a cell with the timestamp Long.MAX_VALUE by mistake (for example HConstants.LATEST_TIMESTAMP misuse). All later normal writes use the current time. Which value does a Get return?

Java A cell with a far-future timestamp (stand-in)

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.

The far-future cell hides every newer real write. You must delete that exact version by timestamp; a normal delete marker at the current time is also older than the bad cell, so it would not hide it. The lesson: let the server assign timestamps unless you have a deliberate reason (column families and versions).

Interview questions with answers

What is HBase, and when would you choose it over a relational database? A distributed, sorted, versioned, wide-column store on HDFS, based on the Bigtable design. Choose it for very large tables (billions of rows), high write throughput and key-based or range access, when you can design around the row key and do not need joins or multi-row transactions.

Explain the write path. Client finds the region through hbase:meta (cached), sends the Put to its region server; the edit is appended to the WAL on HDFS and then written to the MemStore; the client gets an acknowledgement. When the MemStore fills it flushes to an HFile; compactions later merge files (Compactions and Flushes).

Explain the read path. The region server merges results from the MemStore, the BlockCache and HFiles, using Bloom filters and key ranges to skip files, and returns the newest versions.

What is a hotspot and how do you avoid it? Skewed traffic on a key range, usually from monotonic or low-cardinality key prefixes. Use salting, hashing, reversing, field swapping and pre-splitting (hotspotting).

What are minor and major compactions? Minor merges some small files; major rewrites all files of a store, and is the only one that purges deletes, TTL and extra versions.

How does HBase guarantee consistency? Reads and writes of one row are atomic and strongly consistent (a row is served by one region server). Operations across rows or tables are not atomic. Multi-region transactions are not built in (Phoenix with Tephra or Omid adds them).

What does deleting a row do? It writes a tombstone; data disappears at major compaction.

How many column families should you use and why? Few (one to three), because each has its own MemStore and HFiles and flushes happen together.

How do you do an atomic counter? Increment, or incrementColumnValue, atomic per row.

What is the difference between HBase and Cassandra? Both are wide-column stores with LSM storage. HBase has a master, strongly consistent single-row operations and HDFS as storage; Cassandra is masterless with tunable consistency and its own storage. Choose by consistency model, ecosystem and operations.

How would you copy a production table to a test cluster? Snapshot, ExportSnapshot, then clone_snapshot on the target (Backup, Snapshots and Replication).

How do you load 10 TB quickly? Bulk load: a MapReduce or Spark job writes sorted HFiles per region, then BulkLoadHFiles (Bulk Loading HFiles).

A design-review checklist

Use it on any new table:

  1. List queries and the key prefix for each.
  2. Check key distribution for hotspots; pre-split.
  3. Keep keys and qualifiers short.
  4. Few column families; separate by lifetime and size.
  5. Versions and TTL chosen on purpose.
  6. Compression, encoding, Bloom filter and block size set.
  7. Plan for backups (snapshots) and for restores.
  8. Know how analytics will read it without hurting online traffic.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which key prefix is the most likely to cause a hotspot?

    An always-increasing prefix sends every new write to the last region.
  2. 2. A cell was written with a far-future timestamp. What happens to later writes?

    Newest means highest timestamp, so the bad cell masks later normal writes.
  3. 3. What is atomic in HBase?

    Single-row operations are atomic; multi-row operations are not.
  4. 4. Which tool copies a table's files to another cluster with the least load on the source region servers?

    ExportSnapshot copies HFiles directly, bypassing the region servers' read path.
  5. 5. Why is a low-cardinality first key field a problem even if it is not monotonic?

    A skewed or low-cardinality prefix concentrates traffic on a few key ranges.

Summary

  • Practice by testing key schemes against the region layout, not by intuition.
  • Skew and low cardinality hotspot as much as monotonic keys; let the server assign timestamps.
  • Be able to explain the write and read paths, compactions, consistency and the main tools.
  • Run every new table through the design-review checklist.

Next: back to the Apache HBase track page