Skip to the page
Tecyfy

Data engineering in the AI era · intermediate · About 10 minutes

The table that gets slower every week

A store sales table fed by a stream every 5 minutes took just over a minute to query in its first week and 7 minutes in its sixth. Last year's table holds as much data and answers the same query in 38 seconds.

You run the Databricks jobs behind the store sales dashboard.

What happened

Six weeks ago the store sales table moved from a nightly load to a stream, so the dashboard shows sales within minutes. A streaming job appends to the Delta table sales_2026 every 5 minutes from 400 stores. The table is partitioned by sale_date and store_id.

The year-to-date query behind the dashboard has grown slower every week. The analysts ask for a bigger cluster.

The incident is made up. How things work in it is real, with sources at the end.

The evidence

Everything you need is here. Read it before you decide.

01The table, week by week(Table)
WeekSizeFilesAverage fileYear-to-date query
187 GB806,400108 KB1 min 10 s
2174 GB1,612,800108 KB2 min 20 s
4348 GB3,225,600108 KB4 min 40 s
6522 GB4,838,400108 KB7 min
02Last year's table, loaded once a night(Table)
TableSizeFilesAverage fileSame query
sales_2025520 GB4,160128 MB38 s
03The streaming write(Code)
(events.writeStream
   .format("delta")
   .partitionBy("sale_date", "store_id")
   .trigger(processingTime="5 minutes")
   .option("checkpointLocation", "/checkpoints/sales_2026")
   .toTable("sales_2026"))
04The arithmetic(Note)

A 5-minute trigger is 288 micro-batches a day. Each batch writes at least 1 file into each of the 400 store partitions it touches: 288 × 400 = 115,200 files a day, or 806,400 a week. The stores sell about 12.4 GB a day, so the average file is about 108 KB.

Your decisions

Decision 1 of 3

  1. Decision 1

    Why is the query slower every week?

The ideas behind it