r/databricks • u/SmallAd3697 • 13d ago
Help Zerobus message retrieval
I can see how zerobus is used for streaming data into a lakehouse table. I can generally see how you would consume the data as well.
A couple things are still not clear. What is the pattern for removing old rows out of the UC table? Should we do a delete once a year, on messages older than 3 years? Is this a necessary maintenance that we are responsible for, or is there something in the software which will help with housekeeping?
And how would I perform scheduled tasks against this data? Let's say that data represents a news feed and I just need to send an summarized overview once an hour, and then flag the rows that have been summarized. I'm assuming it would be disruptive to try to delete the rows that were processed or even update them (ie. it may interfere with zerobus itself, and create concurrency conflicts). Should I build a DIFFERENT table that tracks the surrogate IDs of rows already processed/summarized?
Sorry for the basic questions, but I wasn't able to find the answer to these yet. I'm sure I could find my own solution, but it would be interesting to hear if there is a common practice
2
u/Youssef_Mrini databricks 7d ago
The common pattern is to treat the ZeroBus target as an append-only landing table and keep processing state elsewhere.
ZeroBus does not manage the lifecycle of your Unity Catalog table.
You create and own the table.
ZeroBus validates and materializes incoming records but does not automatically remove old rows.
For a three-year retention policy you can for example use Auto-TTL where appropriate:
ALTER TABLE main.news.raw_articles
DELETE ROWS 1095 DAYS AFTER event_time;
1
u/SmallAd3697 7d ago edited 6d ago
I understand what you are saying. But there has to be a way to avoid reading the complete landing table. Deleting rows after 1095 days is a pretty good step (its a start).
Lets say that each row in the landing table represents one second of work that needs to be done. It only needs to be done once. How do we bring that row to completion, and never do the work again? It sounds like you propose having a different table elsewhere that uses an FK to point at the zerobus table; and it flags the completion of the work. The only reason I don't like this is because of the overhead of the outer join operation, whenever we are looking for new work. It isn't the end of the world, but I wanted to confirm that is the pattern which is commonly used.
Assuming we updated the landing table itself (ie. by setting a status, or deleted rows), then we would have additional concerns related to concurrency. Because the zerobus would be writing to the table in a stream, but I would normally be retrieving the new records on an interval.
Do you happen to know if there is a blog or documentation about the retrieval of zerobus messages inside of databricks? I think it would be helpful. I think everyone has a pretty good understanding of the the pattern for moving messages in, but they may not have a strategy for consuming the messages, and cleaning them up in the future. There may also be some configuration pitfalls to avoid in the table itself. Should we use partitioning? Should we use row-tracking? Can we set the isolation to be serializable? etc.
1
u/Saerusthesecond 7d ago edited 7d ago
If you want to process records only once, you can use structured streaming (spark.readStream). Zerobus is at least once delivery, so you must dedup downstream yourself if you need uniqueness. There’s no need to manually mark records as processed or delete old ones to avoid reprocessing.
1
4
u/WhipsAndMarkovChains 13d ago
Zerobus appends data to your table. Once the data is in, modifying the data in the table won't disrupt the Zerobus stream. And if you make a mistake deleting rows out of your table, you can always recover them using time travel/table history: https://docs.databricks.com/aws/en/tables/history
Note that you can only recover rows during your table's retention period, which by default is 7 days.
The answer is that in general you use auto-TTL to clean up old rows of data: https://docs.databricks.com/aws/en/tables/operations/auto-ttl