SpinTheMic
Pro

Databricks · Intermediate

What is Z-ordering in Delta Lake, and how does it compare with liquid clustering?

By Anurag Pandey, Lead Data Engineer ·

The short answer

Z-ordering, run with OPTIMIZE ... ZORDER BY, rewrites files so rows with similar values in chosen columns sit together, which improves data skipping. Databricks now recommends liquid clustering for new tables instead.

Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Say it like this

About 50 seconds out loud. Use it as a model, then put it in your own words.

Delta keeps min and max statistics for columns in each data file. When I filter on a column, Databricks uses those stats to skip files that can't contain matching rows. That's data skipping. It only works well if similar values are stored together. Z-ordering does that: OPTIMIZE table ZORDER BY a few columns rewrites the files so related values end up in the same files, and filters on those columns can skip much more. It works best on columns I filter on often, with many distinct values, and gets less effective as I add more columns. Today, Databricks recommends liquid clustering for new tables. I declare clustering keys on the table, I can change them later without rewriting everything, and it replaces both partitioning and Z-ordering for that table.

What interviewers look for

  • You explain data skipping and file-level statistics first.
  • You know Z-ordering is applied with OPTIMIZE and rewrites files.
  • You know liquid clustering is the current recommendation for new tables.

Common mistakes

  • Calling Z-ordering an index.
  • Z-ordering on many columns, which weakens the effect for each one.
  • Not knowing liquid clustering exists, which makes the answer sound dated.

Follow-up questions to expect

  1. 1How do you choose columns for Z-ordering or clustering keys?
  2. 2Can you combine liquid clustering with partitioning?
  3. 3How would you check whether data skipping is working?
Practice this out loud

Opens this question on SpinTheMic. Start without signing up; sign in free for an AI report card.

Checked against

All interview question guides