Open chriscasano opened 3 years ago
Thanks, @chriscasano! I think we'll probably end up covering the outbox patter and implications as part of the Microservices reference architecture that @WadeWaldron is building and that will then inform Cockroach U courses.
From my perspective, I'd prefer to avoid deleting the data from the Outbox table. It definitely needs to be "flagged" to indicate that a record has been processed, but if the record can be left in place, there are many advantages.
The events that get pushed into the Outbox table represent a rich source of historical data that could be used for a variety of purposes such as:
You can even use that data for disaster recovery. Imagine if a bug introduced data corruption into the current state. You can use the events in the outbox table to potentially reconstruct the state at a certain point. Or you might be able to use it to "undo" the data corruption (by walking back certain events).
It provides you with all of the advantages of Event Sourcing, but without some of the complexity.
There's a lot of potential value in that data, and if possible, I'd avoid deleting it.
cc @mwang1026, @amruss
Thanks Wade. So you know, this workaround was created specifically for a customer that required the data to be deleted.
It this a suggested tutorial, @chriscasano ? In general, we're looking to do a Technical Enablement about best practices around the outbox pattern. I'll set up time with you to chat about the content.
w.r.t. the deleting once emitted, the outbox "canon" or "literature" states to Wade's point that a primary advantage of the outbox pattern is durability of the message (as in, can replay arbitrarily whenever they want to). I think we're a little premature on an outbox tutorial, only insofar as I think we need to figure out some of the best practices (e.g. small batch deletes with limits and upper AND lower bounds on timestamps) and codify them
We have marked this issue as stale because it has been inactive for 18 months. If this issue is still relevant, removing the stale label or adding a comment will keep it active. Otherwise, we'll close it in 10 days to keep the issue queue tidy. Thank you for your contribution to CockroachDB docs!
Chris Casano (chriscasano) commented:
When using the Outbox Pattern with CockroachDB, one issue is cleaning up the outbox table once records have been sent to the proper sink. Otherwise, app developers need to create additional code to clean this up. Instead, a script could run that can compare outbox mvcc_timestamp records to the CDC high water mark of the CDC job to see if records can be deleted from the outbox table. Here is an example of how to set this up:
Goal: Remove records from an Outbox table that have been flushed to its sink.
The idea here is to create a clean up job that removes records where the MVCC timestamp of an Outbox record is past the high water mark of a changefeed.
High Level Steps
1 - Get the list of outbox tables that need TTL 2 - Find the active changefeed for those tables 3 - For each table, delete rows where the mvcc_internal timestamp of the row is < the high water mark of the changefeed
Create a schema to test
Get the list of outbox tables that need TTL
Find the active changefeeds for the outbox tables
Run the TTL delete statements
Clean up
Jira Issue: DOC-1566