A quick recap

Before we dive into the changes, let's take a more in-depth look at the registration function provided by our sample service, and its interactions with external resources. The following diagram outlines the steps that are performed during a single call to the register endpoint:

These interactions are as follows:

  1. User calls the register endpoint.
  2. Our service calls the Exchange Rate Service.
  3. Our service saves the registration into the database.

Now let's consider how these interactions could go wrong. Ask yourself the following:

  • What can fail or become slow?
  • How do I want to react or recover from that failure?
  • How are my users going to react to my failure?

Considering the interactions in our function, two problems immediately come to mind:

  • Calls to the database can fail or become slow: How can we recover from this? We could perform retries, but we have to be very careful about this. Databases tend to be more of a finite resource than a web service. As such, retrying requests could, in fact, degrade the performance of the database even further.
  • Calls to the exchange rate service can fail or become slow: How can we recover from this? We could automatically retry failed requests. This will reduce the occasions where we cannot load an exchange rate. Assuming the business approves, we could set up some default rates to use, instead of entirely failing the registration.

The best change we could make to improve the stability of the system might surprise you.

We could simply not make the request at all. If we were able to change the registration process so that the exchange rate was not needed in this part of the processing, then it could never cause us problems.

Let's assume that none of the aforementioned solutions are available to us in our (contrived) example. The only option we are left with is failure. What happens if loading the exchange rate takes so long that the user gives up and cancels their request? They are likely to assume the registration failed and hopefully try again.

With this in mind, our best course of action is to give up waiting for the exchange rate and not to process the registration any further. This is a process known as stopping short.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.182.221