The outbox pattern is a powerful way of handling transactions in a distributed system. In this post I'll go over an example problem and then how

Utilising the Outbox Pattern with Typescript

submited by
Style Pass
2023-03-24 13:30:02

The outbox pattern is a powerful way of handling transactions in a distributed system. In this post I'll go over an example problem and then how we can solve it by utilizing the outbox pattern.

The business also does not want to end up in a situation where a payment is successfully stored but the shipping info is not as this will result in angry customers.

As shown above, this is straightforward when storing information into the same database as we can lean on traditional transactions.

Fast forward and we've grown and so we need to rethink our tech strategy. Our architects have informed us that we need to "split the monolith" which means that the service that deals with shipping will no longer handle payments.

Instead we will make an api call from our payment service to the shipping service so it can handle the shipping detail. Upon doing this we notice a problem which is illustrated below.

As we are making a call to a different service we can't be sure that the call to shipping service will be successful (If the call times out was it succesfully recorded or not?). There is no retry logic with this approach and api calls within a transaction like this can add a lot of latency to our main user flow as well as cause issues when we try to horizontally scale.

Leave a Comment