I have encountered a problem when storing files to BackBlaze using pre-signed URLs and tracking the uploaded file references in PostgreSQL. The primary issue I faced is that BackBlaze doesn't have events like S3 or minio on pre-signed upload complete. How can I find out if a file has been uploaded successfully and mark it as uploaded in PostgreSQL. Please can someone give me a high-level idea to implement this? Also in advance, I am using the s3 compatibility API from Backblaze
Thanks in advance for the help.
The existing system depends on the client to send an upload complete acknowledgement. In some cases, this has failed and left dangling files in BackBlaze and orphaned records in PostgreSQL.
This is a pretty common eventual-consistency issue that is best solved by cleanup processes after-the-fact.
There are two different problems here:
If you need true transactional consistency you will have a more expensive process where you will need to open a transaction for the database server-side and wait for the file upload to complete. The tricky part will be re-connecting to that transaction on what will most definitely be a second client-side call. I would recommend, if you can't use the above cleanup processes for eventual consistency that you move away from pre-signed urls and upload the file server-side so that you can upload the file inside a database transaction. Trying to connect two different requests to the same connection/transaction is possible, but quite difficult.