I am designing architecture for service like pastebin.com. I plan to store user data on S3 storage and metadata with my own server. So whenever a user requests for some paste creation there are two steps to this:

  1. Store content in S3
  2. Store metadata with local metadata db.

I am thinking what would happen if step 1 succeeds and step 2 fails. When it happens, I have data paste in S3 which I don't have a way to access it, and user will get a failure response back, and he/she can retry and then may get succeeded. But the initial failure has created some data in my storage, and I don't have any metadata and any way to access it.

My question

When we have to perform 2-3 activities where one happens after another, and some activity in between fails, how can we rollback?

  • In general, one way to do a transaction rollback is to save the current state before starting, then if an error happens at anytime, restore that saved state. Or if the individual operations are reversible, reverse the operations that were done before the error in reverse order. Of course, these rollback methods assume that an error won't occur during the rollback itself, which may be a faulty assumption. Jul 20, 2020 at 11:10
  • @DavidSpector then you have the additional problem of what happens if the rollback fails.
    – user253751
    Jul 20, 2020 at 12:59
  • Yes, I just said that. Jul 20, 2020 at 19:15

1 Answer 1


There are three aspects of failure handling applying to your case:

  • Informing the service user (important). Giving a failure response is the correct way to go. Normally, your user isn't interested in the details why the call failed, just the fact that it failed. That aspect is important and you already do it.
  • Leaving the service in a consistent state (important). It's important to leave your service in a state where it can accept new requests (as far as that's possible, depending on the type of failure). Having additional, inaccesible data in some storage typically won't affect future requests. That aspect is important, and I bet your code behaves well in that respect.
  • Cleaning up unused resources (optional). Filling storage with inaccessible data is undesirable. You can either try to remove the data in your error handler or create something like a nightly garbage-collection job that scans your storage for inaccessible data. But if resource cost isn't extraordinarily high, you can as well simply live with a small percentage of garbage. It's up to your decision if you want to spend time on this aspect.
  • It makes sense to ignore these failures as suggested in option 3 as storage as cheap and these scenarios are rare. i will keep a matrices to see if any such scenarios arrive in my system to get notified in future Jul 20, 2020 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.