Synchronous vs Asynchronous

Marva Athatillah
2 min readJul 14, 2022

In a synchronous program, the program code is executed sequentially from top to bottom. This means that if we write two lines of code, the second line of code cannot be executed before the first line of code is executed. We can imagine when we are in the cashier queue. We will not be served before all the queues in front of us have been served, nor will the people behind us have to wait their turn.

In an asynchronous program, if we write two lines of code, we can make the second line of code execute without having to wait for the code on the first line to finish executing. In the real world, we can imagine ordering coffee through a waiter, where while waiting for our order to arrive, we can do other activities such as opening a laptop or writing.

An asynchronous program allows one operation to run while waiting for another operation to complete. We generally use asynchronous operations for large and time-consuming operations, such as fetching data from the internet or an API, saving data to a database, and reading data from a file.

--

--