Short answer: add a Lakehouse Maintenance activity to the pipeline that loads your tables. Point it at a lakehouse and a table, choose Optimize (with V-Order if you like) to compact small files, or Vacuum to delete files the table no longer uses. It runs synchronously, so the next step starts only when maintenance is done.
A Delta table loaded in small batches gets a new set of Parquet files on every run. Reads slow down, and a Direct Lake model has a hard limit on files per table. Until now that meant a notebook with OPTIMIZE in it, a schedule of its own, and hoping it ran after the load and not during it. As a pipeline step it simply runs next.
Why do small files pile up?
Say a pipeline appends to sales every hour and each run writes one file. That is 24 files a day. On capacities F2 to F32, a Direct Lake table may have at most 1,000 Parquet files:
- Files
- Direct Lake limit on F2 to F32
After 41 days the table holds 984 files; on day 42 it passes the limit at 1,008. A Direct Lake on OneLake model then fails to refresh until the table is optimised. A daily OPTIMIZE folds each day's 24 files into a few larger ones and the count stays flat.
How do you set it up?
- 1Copyappends the hour's rows to sales
- 2Lakehouse MaintenanceOptimize with V-Order on sales
- 3Refresh SQL analytics endpointso SQL readers see the new files
- In the pipeline, search the Activities pane for Lakehouse Maintenance and drop it after the Copy step, joined on success.
- On Settings, pick the connection, the lakehouse and the table.
- Choose the operation: Optimize compacts small files into larger ones, and Apply V-Order sorts and encodes them for faster reads. Vacuum removes files no longer referenced by the Delta log.
- Save, then Run or Schedule. The Output tab under the canvas shows each run.
If maintenance fails for a table, the activity fails, so an on failure path can send an alert before the next load piles on more files.
When do you run Optimize, and when Vacuum?
- after each large load or once a day
- compacts files
- V-Order costs about 15% more write time and can give up to 50% more compression
- once a week is plenty
- deletes unreferenced files older than the retention, 7 days by default
- frees storage
Optimize does not delete the old small files; it writes new large ones and the Delta log stops pointing at the old ones. That is why Vacuum exists: it removes them once they are older than the retention period. Keep the 7 days unless you have a reason. A shorter retention cuts Delta time travel and can break a reader that is still on an older version, and Fabric refuses anything under 7 days unless you turn the check off in your Spark environment.
The same two commands, for a notebook or a table's Maintenance menu in the lakehouse explorer:
OPTIMIZE sales VORDER;
VACUUM sales RETAIN 168 HOURS;168 hours is the 7 days written out.
What goes wrong?
- A lakehouse with schemas. The activity does not support schema-enabled lakehouses yet. Until it does, keep the notebook for those tables.
- A Private Link workspace. The activity does not run there yet either.
- Vacuum with a short retention. Time travel to before the retention fails, and so does a long query that started on an old version. Seven days is the safe floor.
- Optimize while the load still runs. Two writers on one table can conflict. Chain maintenance after the load with an on-success arrow instead of giving it its own schedule.
Where can you check this?
- Microsoft Learn: Lakehouse maintenance activity
- Microsoft Learn: Run Delta table maintenance in lakehouse
- Microsoft Learn: Refresh SQL analytics endpoint activity
- Microsoft Learn: Direct Lake overview
Where do you start?
Open the lakehouse, look at your most often loaded table and count its files; if it is in the hundreds, add the activity after its load today. What V-Order does to the files is in Delta tables and V-Order in Fabric, and why the file limit matters in Direct Lake: Power BI reports straight from the lake.