Cloud Functions are essentially small Node scripts that use the Admin SDK to access Firebase. They have no special powers beyond the API, which means they have the same limitations as using that API in other places.
Using a Cloud Function will reduce the chances of having an interruption between the related operations, but it does not eliminate that chance.
This means that you'll have to deal with the interruptions in some way. Typically this is a two-step process:
- Ensure that all code reading the data is robust against having incomplete data. For example, after reading the (download) URL from the database, don't assume that the file it points to exists. It might not exist for many reasons (deleted afterwards, service unavailable, etc), so this is a good idea anyway.
- Periodically run a script that detects incomplete data and cleans it up. For example, run a Cloud Function every day that gets a list of all files in Cloud Storage, and removes them if there are no references to them in the database, and that then reads all URLs from the database, and checks if they still exist.
I'll admit that the second step is often something I add later. The first step already ensures the apps run fine anyway, so the cleanup is just some data storage optimization at that point.