ACID implies Atomicity, Consistency, Isolation and Durability, and it’s at the heart of being able to create transactions, where either the entire process is successful, or the entire process is discarded. To give you an example of why this is important, imagine you have an application which allows people to order things online. Typically its purchasing process would look like this.

  1. Customer clicks the buy button
  2. The order is internally handled and shipped
  3. The system deducts money from the customer’s bank account

If step 3 above fails, you have a problem. Maybe the customer didn’t have sufficient finances to make the purchase? Still step number 2 was already executed at that point, and the order had been handled and processed. Your system has now entered an undetermined and invalid state, resulting in you probably loosing money.

For the above example, the fix is really simple. Just make sure you reorder your steps, such that the process becomes the following instead.

  1. Customer clicks the buy button
  2. The system deducts money from the customer’s bank account
  3. The order is internally handled and shipped

Typically deducting money from a bank account is an external service, often provided by a third party payment service providers. While the internal handling of the order, is an internal process, where state changes are applied to the internal system. And in fact, a general “design pattern” can be deducted from the above, which is as follows.

If you follow the above simple rule, you’ve eliminated 50% of the problems related to partially failed micro service systems invocations, where you’re dependent upon several sub-processes being able to finish their tasks, before the task as a whole is considered a success.

Idempotency

Idempotency is a really cool word. It implies that given the same input arguments, a function invocation will only change state the first invocation. The most famous use of this word, is in the HTTP standard and how it describes the PUT verb. The PUT verb should not apply further state changes in a system, if it’s given the same payload twice. Only the first invocation should apply state changes.

In more complex micro service processes, the code executing when a client clicks the “Purchase button”, typically invokes several micro services. Imagine something as follows.

  1. User clicks the purchase button
  2. Money is deducted from the client’s account
  3. Money is transferred to the manufacturer’s account
  4. The order is handled internally, and shipping is started

#microservice #cloud #aws #developer

How to Implement ACID in a MicroService Architecture
7.35 GEEK