Sync vs. Async Code: It’s like making coffee… But without coffee
By: Aarjit
If you’ve ever been on a super slow website waiting for it to load, you’ve probably experienced the problem with synchronous code.
By default, most code runs synchronously. This means it executes line by line, from top to bottom. The computer won’t move to line two until line one is completely finished.
Imagine a coffee shop running synchronously. You walk up, order a venti ice cappuccino latte with dragon fruit or whatever, and stand right at the register. The cashier turns around, steams the milk, does all the barista-ey stuff, and then finally asks the next person in line what they want. Obviously, the line would be extremely long, and everyone would hate you for ordering that complex drink.
In programming, if your app needs to download a big file or fetch data from an API, a synchronous program just stops and is just kinda chilling there until that task is done. The whole app freezes because it’s waiting for some slow code to finally finish.
Then, there’s asynchronous code. Async code lets your program start a slow task, put it on the back burner, and keep doing other things while it waits.
Let's go back to the coffee shop: You order your latte. The cashier takes your money and hands you a receipt with an order number. In JavaScript, this receipt is called a Promise. It's exactly what it sounds like. It’s literally a promise that eventually, you will get a result (either your finished coffee or an error saying the espresso machine broke).
You then proceed to awkwardly stand on your phone to the side while waiting. The cashier immediately takes the next person's order. The coffee shop (your program) keeps running smoothly.
When your coffee is finally ready, the barista calls your number. Typically, in code, we use keywords like async and await to handle this. You’re basically telling your program, "Start this heavy task, and I'll await the result whenever it finishes, but keep the rest of the app running in the meantime."
By making slow tasks async, your apps stay fast, buttons stay clickable, and nobody has to wait for 10 hours to get their blue moon venti ice cappuccino latte with oat milk.

