Skip to the stories
Microsoft 365 & SharePoint

Dr Lakehouse Monitors Fabric Tables and Verifies OPTIMIZE Results

By Nikola 800 views

Dr Lakehouse scores Delta table health across Fabric, queues guarded maintenance and rescans treated tables to confirm results.

Dr Lakehouse Monitors Fabric Tables and Verifies OPTIMIZE Results

Fabric lakehouse tables can slow down without ever reporting an error. A pipeline may finish successfully while its writes leave behind hundreds of small files, soft-deleted rows or a transaction log that takes longer to replay. Those conditions add work for queries and can delay Direct Lake reports: one reported example took 15 seconds to load data from a table with more than 2,000 small files, then fell below one second after the table layout was optimized.

🙂

Dr Lakehouse is a tool built to find that kind of gradual decline across a Fabric tenant, recommend what to do and check whether maintenance improved a table. Its central idea is practical: a green pipeline or a successful maintenance job does not, by itself, prove that the data is in good shape.

Why table health changes over time

A Fabric lakehouse table is a Delta table: Parquet data files accompanied by a _delta_log transaction log. Each write creates at least one Parquet file and a new log commit. That design supports transactions and time travel, but it also means ingestion patterns and maintenance choices shape the table’s physical layout.

Small, frequent writes can create many files. For example, a pipeline that appends a few thousand rows every 15 minutes can produce almost 100 small files a day. A query then has more files to open and read. On a cold Direct Lake load, each file and row group also adds work as column data is loaded into memory.

Other issues can accumulate quietly. With deletion vectors enabled, a DELETE or UPDATE can mark rows as deleted without immediately rewriting the Parquet file; readers still need to skip those rows. If writers do not create checkpoints, the engine may need to replay an increasing number of JSON log files to establish the table’s current state. And tables that have never received OPTIMIZE can retain a poor file layout from their initial ingestion.

These problems often leave pipelines green. They show up instead as slower queries and reports, sometimes long after the ingestion change that caused them. By the time users notice, the team may not know which pipeline, notebook or one-off adjustment started the decline.

Why scheduled OPTIMIZE is not enough

Fabric offers ways to run OPTIMIZE: teams can add it after ETL in a notebook activity, or use the lakehouse explorer’s Maintenance option to run OPTIMIZE and VACUUM on one table. The challenge is deciding which tables need attention.

A fixed maintenance list can spend capacity rewriting healthy tables while missing tables that were never added to the list. In a large tenant, that might include a colleague’s lakehouse, a temporary ingestion area that became operational, or a workspace created for a proof of concept that now contains production data. The explorer handles one table at a time in one lakehouse and does not provide a record of who ran each action.

Dr Lakehouse was designed to cover the gap between diagnosis and maintenance. It scans the tables its service account can access, identifies issues, prescribes a response and lets an operator request maintenance from the same interface. It also rescans after treatment, because a job’s success status does not always mean the table changed.

Scanning and scoring tables

A Python notebook called drl_collect runs once a day, with on-demand scans also available. For each lakehouse, it refreshes SQL analytics endpoint metadata, then combines Fabric’s health information with details read from the Delta log.

  • Fabric health metrics: The SQL analytics endpoint’s sys.sp_get_table_health_metrics procedure returns file count and size, physical and deleted row counts, checkpoint version, and Fabric’s assessment of table problems.
  • Delta history: The notebook uses the deltalake Python library to check the last OPTIMIZE and VACUUM, the number of table versions, whether V-Order is enabled and whether deletion vectors are on.

Each table starts with a score of 100. Dr Lakehouse deducts points for detected conditions, with thresholds kept in a table so teams can adjust them without changing the code.

ConditionWhen it appliesPoints deducted
Small filesAverage file size is under 128 MB, and the table is large enough to compact40
Deleted rowsMore than 10% of stored rows are soft-deleted30
Invalid statisticsFabric reports that statistics cannot be used30
Fabric flagFabric identifies another table problem20
Stale checkpointMore than 10 commits have occurred since the last checkpoint, and the table is large enough to compact15
No recent OPTIMIZEThe table has had no OPTIMIZE for 30 days, has more than 20 commits and is large enough to compact10

Scores from 80 to 100 are classed as healthy; 50 to 79 need attention; below 50 is critical. The tool also turns findings into prescriptions. A table with small files and more than 200 commits gets a recommendation to fix the ingestion batch size and use OPTIMIZE as a stopgap. Repeatedly compacting a table will only provide temporary relief if its pipeline keeps writing tiny batches.

The Priorities page accounts for both score deficit and table size. It ranks a 500 GB table scoring 60 ahead of a 5 MB table scoring 20, reflecting the larger table’s potential impact.

Guardrails for maintenance

Dr Lakehouse submits maintenance through Fabric’s table maintenance job and REST API. OPTIMIZE with V-Order is the default. VACUUM is restricted to admins, requires a confirmation and has a minimum retention period of 7 days. VACUUM permanently deletes files, and the API has no dry run, so the extra confirmation provides a checkpoint before that operation.

Requests enter a queue with limits intended to prevent a bulk selection from overwhelming capacity. The default daily rewrite budget is 500 GB; the selection bar estimates how much of today’s or tonight’s budget a proposed selection would consume before the user submits it. No more than three jobs can run at once in a lakehouse. A table also has a 12-hour cooldown between OPTIMIZE jobs and a lock that prevents two treatments from running on it simultaneously.

The system requires a scan less than 24 hours old before acting. Admins can set protection locks on a workspace or lakehouse: locked tables remain visible and are still scanned, but cannot be treated. Rules are checked both when someone submits a request and again immediately before it is sent to Fabric. A lock added later can therefore stop a previously scheduled treatment from running.

There are three roles. Viewers can see the information but cannot run actions. Operators can scan and treat tables. Admins can also run VACUUM, manage locks and assign roles. Each request is recorded with the requester, time and outcome.

After a treatment succeeds, Dr Lakehouse schedules a rescan of the affected table about five minutes later. If several tables were treated in sequence, their rescans can be grouped. That follow-up checks the result on the table itself rather than treating the job’s status as proof of improvement.

How the components fit together

The collector notebook writes current table health, daily snapshots and lakehouse trends to a monitoring lakehouse. The app is built with Rayfin, using a React frontend and user data functions. Those functions run as a service account, which needs access to client workspaces; individual users need access to the app.

A separate Fabric SQL database, drl_control, stores the maintenance queue, roles, locks and audit trail. The second notebook, drl_driver, processes scans and treatments. The app starts it when a request is queued, and a scheduled run at 01:00 picks up work planned for the night. It checks running jobs, releases locks, queues rescans and submits ready work, then exits when nothing is running or due.

The separate database keeps control rules behind the app’s functions. Rayfin’s built-in data service runs queries with the caller’s permissions; using it for the queue would require each user to have write access to queue and role data. The separate database lets the functions manage that data without giving app users a direct path to change their own permissions.

What the build revealed about Fabric

A successful OPTIMIZE can leave small files in place. In tests, a table with 16 tiny files and another with 13 files both returned a Succeeded status, but still had the same file counts and no OPTIMIZE entry in the Delta log. Fabric’s fast optimize behavior checks whether compacting a group of files is worthwhile. By default, it compacts a group only when it has at least 50 small files or enough data to produce a properly sized file, around 1.3 GB with default settings. Smaller groups may be skipped even though the job succeeds. Dr Lakehouse therefore flags small files only when a table is large enough to compact, and verifies the result with a rescan.

Fabric pipeline Functions activity could not call the app functions. The initial plan was to use a pipeline every five minutes, but requests failed with a missing x-ms-rayfin-info header. Rayfin functions accept calls from the app itself, so the queue driver moved to a Python notebook that works directly with the control database and Fabric API.

Frequent polling kept the SQL database active. The first driver ran every five minutes. A Fabric SQL database remains online until it has been idle for 15 minutes and, while online, uses at least about 0.67 vCore, roughly 1.7 CU. Polling every five minutes would keep the database from idling and consume most of an F2 around the clock, even with an empty queue.

A Fabric Warehouse was considered for the queue, but it did not meet two requirements: concurrent updates to the same table can fail under snapshot isolation, and Warehouse primary keys are NOT ENFORCED. The queue instead stays in the SQL database while the driver runs on demand, checks work every minute while active and exits when it has nothing to process. A 01:00 scheduled run handles the night queue; between uses, the database can pause after 15 minutes. One implementation detail for code connecting to a lakehouse SQL analytics endpoint: the database’s Initial Catalog is the lakehouse name, not its ID.

Capacity and editions

The drl_control database is online while the app is in use or a treatment is running, then remains online for the 15-minute idle period. OPTIMIZE work itself is not an extra cost unique to Dr Lakehouse; it consumes capacity whether launched from a pipeline, the lakehouse explorer or the tool. The difference is that Dr Lakehouse aims to target tables that need maintenance.

The free Community edition is available on GitHub under the Elastic License 2.0. It includes scanning, health scores, prescriptions, in-app OPTIMIZE and VACUUM, and the described guardrails. Teams can run and modify it in their own tenant, but cannot offer it as a hosted service to others.

Dr Lakehouse Pro adds a treatment ledger with before-and-after details per table and CU spent, a daily CU budget, storage reclaim planning, a Direct Lake guard that prioritizes tables behind semantic models, help correcting ingestion settings that create small files, an installer and support.

For Fabric teams, the operational takeaway is to keep planned OPTIMIZE work in the pipeline where it fits, while also checking whether maintenance is reaching the tables that need it and changing their condition. A table health score can direct attention; the rescan is what shows whether the treatment worked.

Source: Nikola · data-mozart.com

From the same basket