Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Databricks · Databricks Data Engineer Professional

The right to be forgotten and purging data

Databricks Data Engineer Professional · Lesson 18 of 21 · 2:20:57

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the Databricks Certified Data Engineer Professional exam. In this lesson: the right to be forgotten, purging deleted data from the files with REORG and VACUUM, and designing tables and pipelines for deletion. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Forget me

At Quayside Eats, a customer asks to be forgotten. Their email address sits in bronze, silver, and gold tables, in landing files, and in an operational database. This lesson covers the right to be forgotten, purging the files, and designing for deletion.

The right to be forgotten

Laws like the GDPR and the CCPA give people the right to have their personal data erased, within a set time. In a Delta table, a delete creates a new version, and the older versions and their files still hold the data. Start in bronze, with a scheduled job that reads a table of erasure requests, and removes the matched customers in one merge, with when matched then delete. Then carry the deletes to silver and gold, for example from the change data feed, and give each streaming table its own delete, with its source read through skipChangeCommits, so the stream does not fail. And check the sources upstream too, like landing files and operational databases, or the next load brings the data back.

Purging the files

With deletion vectors, a delete only marks the rows as deleted, and the data files still hold them. The table history also keeps the deleted rows for thirty days by default, ready for time travel. Reorg table, with apply purge, rewrites the files without the deleted rows, for Delta tables, materialized views, and streaming tables. Then vacuum removes the old data files that are past the retention period, seven days by default, which also limits time travel to those seven days. Predictive optimization is the recommended way to maintain managed tables, and without it, pipelines maintain their streaming tables and materialized views within twenty four hours of an update. So the order is: delete, then reorg with apply purge, then vacuum.

Designing for deletion

Design for deletion from the start: join on a surrogate key, like a customer ID, rather than on the email address. Keep personal data in a few separate tables, so that a request touches fewer places. Track each request, with the tables it reached and the date it was done, to prove it. And remember that clones, exports, and shares can hold copies too.

Recap

Let's recap. The right to be forgotten requires erasing personal data within a set time. A delete only adds a version, so erase with a scheduled merge in bronze, then carry it to silver, gold, and the sources. Reorg with apply purge rewrites the files that deletion vectors only marked, and vacuum removes the old files. Keep the order: delete, purge, then vacuum. And join on surrogate keys, with personal data in a few tables, to make requests simpler.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Quayside Eats receives erasure requests every day, and stores them in a requests table. What is the best way to remove those customers from the bronze customers table?

    • One DELETE per request, typed by hand
    • Overwrite the table every night from the source
    • A scheduled MERGE with the requests table and WHEN MATCHED THEN DELETE
    • A row filter that hides the requested customers
    Show the answer

    A scheduled MERGE with the requests table and WHEN MATCHED THEN DELETE

    A scheduled merge, with when matched then delete, removes every requested customer in one pass. “One DELETE per request, typed by hand” would be slow and error prone, with one statement typed by hand for each request. “Overwrite the table every night from the source” would rewrite the whole table every night, at a far higher cost. And “A row filter that hides the requested customers” would only hide the rows, which are still stored.

  2. A team deleted a customer's rows from a table that uses deletion vectors, and must make sure that the data files no longer hold them. Which commands should it run?

    • ANALYZE TABLE … COMPUTE STATISTICS
    • VACUUM alone
    • DESCRIBE HISTORY on the table
    • REORG TABLE … APPLY (PURGE), then VACUUM
    Show the answer

    REORG TABLE … APPLY (PURGE), then VACUUM

    Reorg with apply purge rewrites the files without the deleted rows, and vacuum then removes the old files. “ANALYZE TABLE … COMPUTE STATISTICS” would only compute statistics for the optimizer. “VACUUM alone” would leave the marked rows in the current files, which vacuum does not remove. And “DESCRIBE HISTORY on the table” would only list the versions of the table, and remove nothing.

  3. Quayside Eats joins its orders, reviews, and loyalty tables on the customer email, so each erasure request means rewriting many tables. What design makes these requests simpler?

    • Hash the email in every table
    • A customer ID as the key, and the email in one table
    • Run VACUUM more often
    • Partition every table by email
    Show the answer

    A customer ID as the key, and the email in one table

    With a customer ID as the key, only one table holds the email, so a request touches far fewer places. “Hash the email in every table” would still leave personal data in every table, since a hashed email can be linked back to the person. “Run VACUUM more often” would remove old files, but the email would still be in many tables. And “Partition every table by email” would make many tiny partitions, and still spread the email everywhere.