Introduction
I wrote this post because i spend a lot times fixing my own script issues installing, deploying and in some apps code. The problem always was bad practices.
An idempotency operation is an action that gives the same result no matter how many times you repeat it. This is useful in many areas of programing and system design.
SQL Queries
In SQL, you can make your queries idempotent by first checking if the data you want to check alerady exist. For example, before updating a record, verify if it’s there. This way, running the same query multiple times won’t cause errors or unwanted changes.
Simple Example - Create a table:
|
|
Bash
When working with distributed system(vm machines, creating automated scripts), operations may not always happpen instantly. Sometimes the same request migth be sent multiple times. To execute idempotent commands you have to read more in detail.
Simple example - Create a table:
|
|
Docker
When writing a Dockerfile. It’s good practice to make sure all commands are idempotent. This means running the build process multiple times won’t create unexpected issues with our app.
|
|
I hope this blog has been a bit helpful, I’ll give a talk this week and it makes me nervous and writing relaxes me.