DEV Community

Cover image for Practical Backward Compatibility example
Sibelius Seraphini for Woovi

Posted on

Practical Backward Compatibility example

Backward compatibility is when your new code/data works well with the old code/data.

Backward compatibility let you validate if the new code/data works as expected, before removing the old code/data.

In addition, backward compatibility is safer than hard migrations and breaking changes

Example of using backward compatibility and not using

Imagine that you decide to move some refund status from status to another field refundStatus

To check if a transaction was refunded or not, you would have this code

const isRefunded = transaction.status === TRANSACTION_STATUS.REFUNDED;
Enter fullscreen mode Exit fullscreen mode

if you do not care about backward compatibility, your new code would be:

const isRefunded = transaction.refundStatus === TRANSACTION_STATUS.REFUNDED;
Enter fullscreen mode Exit fullscreen mode

The problem is the code above is that you assume that all the transaction status was already migrated to refundStatus.
This is a valid assumption if you have a few transactions in a database.
However, at scale you can have millions of transactions and the migration will take a long time.

You need to deploy both backend and frontend to ensure that your new code works as expected

  • you run the migration first
  • deploy backend and frontend

The time between the migration and the release will make the old transaction.status do not work.
So nobody will be able to check if the transaction was refunded or not.

Another approach is like this:

  • deploy backend and frontend
  • you run the migration first

The time between the release and finishing running the migration will make transaction.refundStatus not exist.
So nobody will be able to check if the transaction was refunded or not.

The only way to make sure this code will work is to make it backward compatible

const isRefunded =
  transaction.refundStatus === TRANSACTION_STATUS.REFUNDED ||
  transaction.status === TRANSACTION_STATUS.REFUNDED;
Enter fullscreen mode Exit fullscreen mode

Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.

If you want to work with us, we are hiring!


Photo by Julia Craice on Unsplash

Top comments (0)