As has been mentioned previously (see here, here, and here, for example), bulk operations in Bubble are not performant. Even the recommended approach of recursive back-end workflows on a list are a frequent source of Bubble’s grating “Workflow Error - Sorry we ran into a bug. Try back later”. This log message shows up for lists larger than a few hundred items during execution of workflows with immediate iteration. From our experience this log message is actually a symptom of back-end capacity limits timing out a workflow, and not an actual error in any workflow. Even Bubble’s own documentation cautions against the liberal use of making changes to large lists.
Parent-child relationships between database tables in Bubble offer a special case of this problem. In this case we want deletion of a single parent record to cascade to the deletion of a (very) large number of child records. We have been able to successfully “hack” a solution that satisfies the following constraints:
- Bulk deletes of the child records of a parent record have to look immediate on the front-end.
- Actual garbage collection needs to be throttled and deferred to off peak load times. Even if it takes hours behind the scenes.
- We cannot rely on directly modifying any fields, because of the capacity limitations of back-end bulk workflows.
We have experimented, and failed to varying degrees, with six different techniques:
- The obvious, delete a list of things. When used on the client-side, with sufficiently large lists this will hang the browser. On the server-side we frequently hit the ambiguous “Workflow Error - Sorry” message. When there are more than a few hundred records we find that workflow will fail on about 20% of the list items.
- Next we tied flagging records for eventual garbage collection using make changes to a list of things. This faces the same issues. Either hanging the browser on the front-end. Or failing on about 20% of records when run on batches larger than a few hundred.
- We tried to schedule a workflow on a list, where the workflow deletes each item. Again the same 20% failure rate above a few hundred records.
- We tried to schedule a workflow on a list flagging records for eventual garbage collection. We still hit the 20% failure rate above a few hundred records.
- We next set up a recursive workflow where each iteration was run immediately, deleting the items on the list. Even with explicit recursion the deletes failed about 20% of the time when the list was more than a few hundred records.
- Finally we tried recursive workflows with immediate iteration to flag for eventual garbage collection. This attempt resulted in the same 20% failure rate.
Our only success was to explicitly iterate operations with a one second delay between iterations, and between all other workflow invocations for good measure.
This presented us with a problem. How do we signal to the front-end user that the child records are at least intended for deletion, when the only way to ensure deletion was to introduce a one second delay into every workflow invocation?
The key insight for us was that a reference to a parent record in a child record is set to empty as soon as the parent record is deleted. Note that this is not true for lists. Deleting an underlying “thing” referenced in an explicitly constructed list does not remove the reference from the list. Even though the reference is now invalid.
Our insight constrained the problem of immediate front-end notification of deletion down to setting up the appropriate search restrictions on child records. In our all displays of child records we require the reference to the parent record to be not empty. Our setup works as follows:
- We create a parent table, for example records of uploaded files
- We create a child table, for example results extracted from the files
- We create a field in the child table that references the parent record in the parent table, for example
Result's Source File.
- When the child record created we immediately populated the parent reference field, for example
Result's Source File = A Parent File.
- We constrain the front-end to display only child records where the parent reference field is not empty, for example
Result's Source File isn't empty.
- When a parent record is deleted Bubble automatically sets all the references to the record to empty, important to note this happens for singular database fields only, not explicitly constructed lists.
- During off peak times we slow drip the garbage collection of child records with an empty parent field.
The deeper “theoretical” reason this works is that we are determining a priori, when the record is created, which records can be bulk deleted together. When specifying arbitrary criteria for choosing records for bulk deletion this method is much more awkward.