I have a scenario where I have an image from a user on a mobile device and some accompanying data. I'm using Amazon Web Services and the idea was to store the image in S3 and the data into a database table.
I'm processing this data using Node JS.
To store the image onto S3, I am using the AWS SDK. To store the record into MySQL I am using the 'mysql' NPM package.
The Problem
What is the best practice way to ensure both events run smoothly, and if not, make sure none take place. So let's imagine the S3 putObject has finished and was error free, but the MySQL insert timed out.
The Solution
I can come up with many - and have done in the past. The real problem here is what I would consider best practice, and after researching on stack overflow, I can't seem to find a good scenario or best practice answer to the question:
"What is the best way to handle errors when a single function involves two or more (potentially error prone) remote dependencies?"
I was just wondering if anybody had the answer to this?
Thanks all