DEV Community

Cover image for Synchronous vs Asynchronous
Shishir Bhuiyan
Shishir Bhuiyan

Posted on

Synchronous vs Asynchronous

Most people understand technical concepts better when they connect to real-life experiences. One of the simplest ways to explain synchronous vs asynchronous programming is through railway ticket booking in Bangladesh.

Imagine buying a long-distance train ticket at Kamalapur Railway Station. This is a classic synchronous process. You stand in a single queue and wait for your turn. When you finally reach the counter, the clerk checks seat availability, processes payment, and prints the ticket while everyone behind you waits. The system handles one passenger at a time. If the network becomes slow or someone takes extra time deciding, the entire line stops moving because every step depends on the previous one finishing first.

Now compare that to an online railway ticket booking system. Thousands of people can search routes, check seat availability, and make payments at the same time. When you click “Book Ticket,” your request is sent to the server and processed in the background. While your payment is being verified, the platform continues serving other users simultaneously. You are waiting for your own response, but you are not blocking the entire system.

That is essentially how asynchronous programming works. When a function is marked as "async," it tells the system that this task may involve waiting—perhaps for a database query, an API response, or a payment gateway confirmation. When we use await, that specific function pauses until the result arrives, but the rest of the application continues running other operations in parallel. Once the response is ready, execution resumes exactly where it stopped.

Top comments (1)

Collapse
 
tahosin profile image
S M Tahosin

Good breakdown of sync vs async. The callback hell section is relatable, almost every JS dev has been there at some point. If you haven't already, worth looking into how Promise.allSettled() differs from Promise.all() since that trips people up a lot in real projects. Solid first post.