0

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 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 1 is success and 2 fails.Then i have data paste in S3 which i dont have a way to access it and user will get a failure response back and he/she can retry and then it may get succeded. But the initial failure have created some data in my storage for whom i dont have any metadata and any way to access it.

So my doubt is like in such cases where we have to perform 2-3 activity where one happens after another, in case some activity in between fails then 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. – David Spector Jul 20 at 11:10
  • @DavidSpector then you have the additional problem of what happens if the rollback fails. – user253751 Jul 20 at 12:59
  • Yes, I just said that. – David Spector Jul 20 at 19:15
3

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.
| improve this answer | |
  • 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 – rahul sharma Jul 20 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.