An existing blob is harmless, but a database entry pointing to a blob that does not exist will be bad. Therefore, I would execute a transaction with the following logic.
Create ... add blob first, then create the database entry. If the blob download failed, just go back. If the blob download succeeds but the database record failed, delete the blob and return. The fact is that you do not want to create a database record until AFTER a successful blog upload. You also want to clear blob if the database record cannot be updated. If the blob cleanup fails, I just have a service that runs periodically to clear the unrecorded drops created more than an hour earlier so as not to try to delete one between loading and creating a database record.
When deleting ... First delete the database entry. If this fails, just go back, the blob record and the database are still there. If the database record is deleted normally, the drop does not hurt anything, remaining there, so you can either try to delete it immediately, or leave it to the cleanup service to take care later.
source share