<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Abhisek Goswami: Technology</title>
<link>https://abhisek-goswami.com/blog/category/technology/</link>
<atom:link href="https://abhisek-goswami.com/blog/category/technology/rss.xml" rel="self" type="application/rss+xml"/>
<description>Tools, databases, AI and how things actually work.</description>
<language>en-in</language>
<lastBuildDate>Thu, 03 Dec 2026 11:30:00 GMT</lastBuildDate>
<item>
<title>Advantages of Singapore VPS hosting for Asian businesses</title>
<link>https://abhisek-goswami.com/blog/singapore-vps-hosting-for-asian-businesses/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/singapore-vps-hosting-for-asian-businesses/</guid>
<pubDate>Thu, 03 Dec 2026 11:30:00 GMT</pubDate>
<category>Technology</category>
<category>hosting</category><category>vps</category><category>cloud</category><category>asia</category><category>performance</category>
<description>Why Singapore is a strong hosting location for businesses serving Asia, what a VPS adds, and how to choose a provider.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/singapore-vps-hosting-for-asian-businesses.png" alt="Infographic: six reasons businesses serving Asia host in Singapore: low latency, connectivity, stability, data protection, scalability and edge readiness"></p><p>In Asian e-commerce, every millisecond counts. Slow pages lose visitors: study after study links longer load times to lower conversions. For businesses competing across the region, where you host your website is a strategic decision.</p>
<p>This article explains why <strong>Singapore VPS hosting</strong> is a popular choice, and what to look for.</p>
<h2>Understanding the landscape</h2>
<p>Asia is not one market. Businesses deal with:</p>
<ul>
<li><strong>Different cultures and languages</strong>, from East Asia to the mix of Southeast Asia.</li>
<li><strong>Different economies</strong>, from mature markets like Japan and South Korea to fast-growing ones like India and Vietnam.</li>
<li><strong>Different rules</strong> on data, payments and content in every country.</li>
<li><strong>Fast technology adoption</strong>: super-apps, digital wallets and huge e-commerce platforms.</li>
</ul>
<p>Success needs cultural awareness, an agile strategy and reliable technology underneath.</p>
<h2>Why hosting matters</h2>
<p>Your hosting provider directly affects:</p>
<ul>
<li><strong>Speed:</strong> load times shape user satisfaction and search rankings.</li>
<li><strong>Security:</strong> SSL certificates, firewalls and monitoring protect customer data and trust.</li>
<li><strong>Scalability:</strong> you need room to grow during sales and traffic peaks.</li>
<li><strong>Reach:</strong> location and CDN integration decide how fast you are for distant users.</li>
</ul>
<h2>What a VPS adds</h2>
<p>A <strong>Virtual Private Server (VPS)</strong> gives you a dedicated slice of a physical server, with its own CPU, memory, storage and operating system. Compared with shared hosting, you get predictable performance and full control. Compared with a dedicated server, it costs less and scales up in minutes.</p>
<h2>Why Singapore?</h2>
<p>Singapore is often called the gateway to Asia, and for hosting the label fits.</p>
<ol>
<li><strong>Low latency.</strong> Its central location keeps round trips short to Southeast Asia, and reasonable to India, China and Australia.</li>
<li><strong>Connectivity.</strong> It&#39;s one of the world&#39;s densest hubs for submarine cables and internet exchanges.</li>
<li><strong>Stability and reliability.</strong> Mature data centres, reliable power and a stable business environment.</li>
<li><strong>Data protection.</strong> Singapore&#39;s <a href="https://www.pdpc.gov.sg/">Personal Data Protection Act (PDPA)</a> gives a clear, well-enforced privacy framework.</li>
<li><strong>Scalability.</strong> Add CPU, memory and storage as you grow, without moving.</li>
<li><strong>Competitive pricing.</strong> Despite being a premium location, strong competition keeps VPS prices reasonable.</li>
</ol>
<h2>Features worth looking for</h2>
<ul>
<li><strong>Customisation:</strong> root access to install the software you need.</li>
<li><strong>Multi-region networking:</strong> good peering to the specific countries you serve.</li>
<li><strong>Local support:</strong> support in your team&#39;s time zone, and in the languages you work in.</li>
<li><strong>Hybrid options:</strong> connect the VPS to your on-premises systems or other clouds, keeping sensitive data where it must be.</li>
</ul>
<h2>What&#39;s next for Singapore hosting</h2>
<ul>
<li><strong>Edge computing:</strong> more providers are adding edge nodes to cut latency further for gaming, finance and healthcare. See <a href="https://abhisek-goswami.com/blog/edge-computing-vs-cloud/">edge computing in a cloud-dominated world</a>.</li>
<li><strong>Automation and AI</strong> for provisioning, scaling and threat detection.</li>
<li><strong>Stronger security:</strong> wider use of multi-factor authentication, continuous monitoring and, longer term, <a href="https://abhisek-goswami.com/blog/quantum-cryptography-future-of-cybersecurity/">post-quantum encryption</a>.</li>
<li><strong>Greener data centres:</strong> Singapore now approves new data centre capacity with strict energy-efficiency requirements.</li>
</ul>
<h2>Conclusion</h2>
<p>For businesses serving Asia, Singapore VPS hosting combines low latency, strong connectivity, solid security and clear data protection rules. If speed, reliability and regional reach matter to your business, it deserves a place on your shortlist.</p>
<p><em>Related reading: <a href="https://abhisek-goswami.com/blog/secure-rdp-with-ssl-vpn/">Securing remote desktop with an SSL VPN</a>, useful for managing your servers safely.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/singapore-vps-hosting-for-asian-businesses/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
<item>
<title>DeFi lending explained: how decentralised loans work</title>
<link>https://abhisek-goswami.com/blog/defi-lending-explained/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/defi-lending-explained/</guid>
<pubDate>Thu, 03 Dec 2026 10:30:00 GMT</pubDate>
<category>Technology</category>
<category>blockchain</category><category>defi</category><category>crypto</category><category>fintech</category>
<description>What DeFi lending is, how lending pools and smart contracts replace the bank, the main use cases, and the risks to understand first.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/defi-lending-explained.png" alt="Infographic: how DeFi lending works in four steps: lenders deposit, borrowers lock collateral, the smart contract lends, interest flows back"></p><h2>What is DeFi lending?</h2>
<p><strong>Decentralised finance (DeFi)</strong> is financial technology built on blockchains: secure, shared ledgers like the ones behind cryptocurrencies. Instead of a bank in the middle, rules are written into <strong>smart contracts</strong>, programs that run on the blockchain.</p>
<p>DeFi removes many bank fees and office-hour delays. With an internet connection and a digital wallet, people can hold, send and lend money within minutes.</p>
<h2>How it works</h2>
<p><strong>DeFi lending</strong> lets users lend and borrow crypto assets directly with each other:</p>
<ol>
<li><strong>Lenders deposit</strong> crypto into a lending pool managed by a smart contract, and earn interest.</li>
<li><strong>Borrowers lock collateral</strong>, usually worth more than the loan, to protect lenders.</li>
<li><strong>The smart contract issues the loan</strong> automatically. No application form, no approval queue.</li>
<li><strong>Interest flows back</strong> to lenders. Rates move with supply and demand in the pool.</li>
</ol>
<p>If the value of a borrower&#39;s collateral falls too far, the contract can sell it automatically to repay the loan.</p>
<h2>Use cases</h2>
<ul>
<li><strong>Peer-to-peer lending and borrowing.</strong> Anyone can lend idle assets to earn interest, or borrow against crypto without selling it.</li>
<li><strong>Compliance without full identity exposure.</strong> Banks rely on Know Your Customer (KYC) checks, which can clash with DeFi&#39;s privacy goals. Some platforms add <strong>Know Your Transaction (KYT)</strong> monitoring instead, which focuses on transaction patterns and wallet addresses rather than personal identities.</li>
<li><strong>Digital identity.</strong> Pairing blockchain-based digital identities with DeFi could give people without bank accounts access to the global financial system.</li>
</ul>
<h2>Benefits</h2>
<ul>
<li><strong>No middleman:</strong> individuals, merchants and businesses transact directly.</li>
<li><strong>Open access:</strong> anyone, anywhere, with an internet connection.</li>
<li><strong>Transparency:</strong> every transaction is recorded on a public ledger.</li>
<li><strong>Speed:</strong> settlement in minutes, around the clock.</li>
</ul>
<h2>Risks to understand first</h2>
<p>DeFi is powerful but young. Before using it, understand:</p>
<ul>
<li><strong>Smart-contract bugs:</strong> a flaw in the code can be exploited and funds lost.</li>
<li><strong>Volatility:</strong> collateral can be liquidated quickly in a falling market.</li>
<li><strong>Regulation:</strong> rules differ by country and are still evolving.</li>
</ul>
<h2>The future of DeFi lending</h2>
<p>DeFi is growing to mirror much of the traditional financial system: exchanges, lending and borrowing across many asset types. It may not replace banks, but it&#39;s pushing them to become faster, cheaper and more open. To learn more, the <a href="https://ethereum.org/en/defi/">Ethereum DeFi guide</a> is a good starting point.</p>
<p><em>Related reading: <a href="https://abhisek-goswami.com/blog/quantum-cryptography-future-of-cybersecurity/">The rise of quantum cryptography</a>, the next big challenge for the cryptography that blockchains rely on.</em></p>
<p><em>This article is for general information only and isn&#39;t financial advice.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/defi-lending-explained/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
<item>
<title>Unlocking the potential of edge computing in a cloud-dominated world</title>
<link>https://abhisek-goswami.com/blog/edge-computing-vs-cloud/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/edge-computing-vs-cloud/</guid>
<pubDate>Thu, 03 Dec 2026 09:30:00 GMT</pubDate>
<category>Technology</category>
<category>edge-computing</category><category>cloud</category><category>iot</category><category>architecture</category>
<description>Why edge computing complements the cloud rather than replacing it, with examples from retail, healthcare and self-driving cars.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/edge-computing-vs-cloud.png" alt="Infographic comparing edge computing and cloud computing by location, strength, example and how they work together"></p><p>For years, cloud computing has been the backbone of digital transformation. It lets businesses of every size store, analyse and process data at massive scale. But as data volumes explode, a complementary approach is reshaping how we compute: <strong>edge computing</strong>.</p>
<p>The cloud offers centralised scale. The edge offers <strong>speed and proximity</strong>: it processes data close to where it&#39;s created.</p>
<h2>Edge complements the cloud</h2>
<p>Edge computing isn&#39;t a replacement for the cloud. It solves a specific problem: <strong>latency</strong>. When data has to travel long distances to a central server and back, milliseconds add up. In retail, manufacturing and healthcare, those milliseconds can change the outcome.</p>
<p>Edge computing moves part of the processing to devices and local servers near the data source.</p>
<h2>Three examples</h2>
<p><strong>Smart retail.</strong> Cameras and sensors in a store track foot traffic and shelf stock in real time. Sending every video frame to the cloud would be slow and expensive. Processing it in the store means instant alerts, like &quot;aisle 4 is empty&quot;, and only summaries go to the cloud.</p>
<p><strong>Healthcare.</strong> Wearables track heart rate, blood pressure and oxygen levels. Analysing readings on the device or a nearby gateway means abnormal values trigger an alert immediately, even if the internet connection drops.</p>
<p><strong>Self-driving cars.</strong> A car must decide to brake in milliseconds. A round trip to a data centre is far too slow, so vehicles process sensor data on board. The cloud is still used for mapping updates and for training the next version of the driving software.</p>
<h2>Getting the balance right</h2>
<p>The real design question is what to process where:</p>
<ul>
<li><strong>At the edge:</strong> time-critical decisions, filtering noisy data, working offline.</li>
<li><strong>In the cloud:</strong> long-term storage, heavy analytics, model training, fleet-wide updates.</li>
</ul>
<p>The major cloud providers now offer edge services that connect the two, for example <a href="https://aws.amazon.com/what-is/edge-computing/">AWS&#39;s edge offerings</a>, Azure IoT Edge and Google Distributed Cloud. That makes hybrid designs much easier to build.</p>
<h2>The future is both</h2>
<p>As devices multiply and data grows, the question isn&#39;t &quot;edge or cloud?&quot; The winners will combine both: decide locally in milliseconds, then learn globally in the cloud.</p>
<p><em>Related reading: <a href="https://abhisek-goswami.com/blog/data-warehouse-vs-data-lake/">Data warehouse vs data lake</a> and <a href="https://abhisek-goswami.com/blog/singapore-vps-hosting-for-asian-businesses/">Why businesses serving Asia host in Singapore</a>.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/edge-computing-vs-cloud/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
<item>
<title>Data warehouse vs data lake: which one fits your data?</title>
<link>https://abhisek-goswami.com/blog/data-warehouse-vs-data-lake/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/data-warehouse-vs-data-lake/</guid>
<pubDate>Thu, 03 Dec 2026 08:30:00 GMT</pubDate>
<category>Technology</category>
<category>data</category><category>analytics</category><category>data-warehouse</category><category>data-lake</category>
<description>The difference between a data warehouse and a data lake, explained with everyday analogies, plus when to use each.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/data-warehouse-vs-data-lake.png" alt="Infographic comparing a data warehouse and a data lake by data type, schema, best use and an everyday analogy"></p><p>Data drives almost every business decision today, and anything you can record counts as data. To use it well, you need to store it in a way that matches how you&#39;ll retrieve it.</p>
<p>This post compares the two most common approaches, the <strong>data warehouse</strong> and the <strong>data lake</strong>, and helps you pick the right one.</p>
<h2>What is a data warehouse?</h2>
<p>A <a href="https://aws.amazon.com/what-is/data-warehouse/">data warehouse</a> stores <strong>structured, cleaned data</strong> in one central place, organised into tables designed for analysis. Data is shaped <em>before</em> it&#39;s loaded (called <strong>schema-on-write</strong>), so queries are fast and results are consistent.</p>
<p>Analysts use operations like slice, dice and pivot to compare data and build dashboards, which makes warehouses ideal for reporting and business intelligence.</p>
<p><strong>Everyday analogy:</strong> a labelled filing cabinet. Every document is sorted into the right folder before it goes in, so you can find exactly what you need in seconds.</p>
<h2>What is a data lake?</h2>
<p>A <a href="https://aws.amazon.com/what-is/data-lake/">data lake</a> stores <strong>any kind of data in its raw form</strong>: tables, logs, JSON, images, audio and video. Data lakes are usually built on cheap object storage and can grow to enormous sizes. Structure is applied only when you read the data (<strong>schema-on-read</strong>).</p>
<p><strong>Everyday analogy:</strong> your email inbox. It keeps everything: messages, PDFs, photos, spreadsheets. Nothing is sorted on the way in, but with a good search you can still find what you need.</p>
<h2>The key differences</h2>
<table>
<thead>
<tr>
<th></th>
<th>Data warehouse</th>
<th>Data lake</th>
</tr>
</thead>
<tbody><tr>
<td><strong>Data</strong></td>
<td>Structured, processed</td>
<td>Structured, semi-structured and unstructured</td>
</tr>
<tr>
<td><strong>Schema</strong></td>
<td>Defined before loading</td>
<td>Applied when reading</td>
</tr>
<tr>
<td><strong>Speed</strong></td>
<td>Fast, predictable queries</td>
<td>Flexible, but queries can be slower</td>
</tr>
<tr>
<td><strong>Users</strong></td>
<td>Business analysts, BI teams</td>
<td>Data scientists, ML engineers</td>
</tr>
<tr>
<td><strong>Cost</strong></td>
<td>Higher per terabyte</td>
<td>Lower per terabyte</td>
</tr>
</tbody></table>
<h2>When to use each</h2>
<p><strong>Choose a data warehouse</strong> when your data is structured and related, and you need fast, reliable reporting. A library management system is a classic example: books, members and loans link together with keys and power the same reports every week.</p>
<p><strong>Choose a data lake</strong> when you collect lots of varied or raw data, or want to keep everything for future machine learning. Most modern apps, with their mix of user events, images and logs, fit here.</p>
<p><strong>Or use both.</strong> Many companies keep raw data in a lake and load a cleaned subset into a warehouse. Newer <strong>&quot;lakehouse&quot;</strong> platforms combine the two in one system.</p>
<h2>Conclusion</h2>
<p>There&#39;s no universal winner. Match the storage to your data and your questions, and weigh efficiency, security and cost. The model that fits your needs is the right one.</p>
<p><em>Related reading: <a href="https://abhisek-goswami.com/blog/edge-computing-vs-cloud/">Edge computing in a cloud-dominated world</a>, about where data gets processed before it ever reaches your warehouse or lake.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/data-warehouse-vs-data-lake/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
<item>
<title>The rise of quantum cryptography and the future of cybersecurity</title>
<link>https://abhisek-goswami.com/blog/quantum-cryptography-future-of-cybersecurity/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/quantum-cryptography-future-of-cybersecurity/</guid>
<pubDate>Thu, 03 Dec 2026 07:30:00 GMT</pubDate>
<category>Technology</category>
<category>security</category><category>cryptography</category><category>quantum</category><category>pqc</category>
<description>Why quantum computers threaten today&#39;s encryption, how quantum key distribution and post-quantum cryptography respond, and what organisations should do now.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/quantum-cryptography-future-of-cybersecurity.png" alt="Infographic: quantum and cryptography explained, covering the threat, QKD, post-quantum cryptography, who needs it first, the catch and what to do now"></p><p>Data breaches are getting more frequent and more sophisticated. As every industry digitises, protecting sensitive information has become a board-level priority. Traditional encryption has served us well, but a new kind of computer could change the rules. This is where <strong>quantum cryptography</strong> comes in.</p>
<h2>The quantum threat</h2>
<p>Today&#39;s public-key encryption (RSA and elliptic-curve cryptography) relies on maths problems that classical computers can&#39;t solve in any reasonable time. A large, error-corrected <strong>quantum computer</strong> could solve them, in hours rather than millions of years.</p>
<p>No machine that powerful exists yet. But attackers can <strong>&quot;harvest now, decrypt later&quot;</strong>: copy encrypted data today and wait. Anything that must stay secret for 10+ years, like medical records, state secrets or financial data, is already at risk.</p>
<h2>Two answers: QKD and post-quantum cryptography</h2>
<h3>Quantum key distribution (QKD)</h3>
<p>Quantum cryptography uses the physics of light itself. In <strong>quantum key distribution</strong>, encryption keys are sent as photons in quantum states. Because measuring a quantum state changes it, any attempt to intercept the key <strong>disturbs it and is detected</strong>. The two parties can then throw that key away and try again.</p>
<h3>Post-quantum cryptography (PQC)</h3>
<p>PQC takes a different route: new mathematical algorithms that resist both classical and quantum attacks and run on today&#39;s hardware. In <strong>August 2024</strong>, NIST published the first three <a href="https://csrc.nist.gov/projects/post-quantum-cryptography">post-quantum standards</a> (FIPS 203, 204 and 205). Browsers, messaging apps and cloud providers are already rolling them out.</p>
<p>The two approaches complement each other: QKD for high-security links, PQC for everything else.</p>
<h2>Who benefits first</h2>
<ul>
<li><strong>Financial institutions:</strong> protecting transactions and customer data that must stay confidential for years.</li>
<li><strong>Governments:</strong> securing classified communications.</li>
<li><strong>Healthcare:</strong> keeping electronic health records private for a patient&#39;s lifetime.</li>
</ul>
<h2>The challenges</h2>
<p>QKD needs specialised hardware and dedicated fibre or satellite links, and it works over limited distances, so it&#39;s expensive. Organisations also need people who understand both cryptography and quantum physics. Research is bringing costs down, but for most companies PQC is the practical first step.</p>
<h2>What to do now</h2>
<ol>
<li><strong>Inventory your cryptography.</strong> Know where you use RSA and ECC: TLS, VPNs, code signing, databases.</li>
<li><strong>Plan for crypto-agility.</strong> Design systems so algorithms can be swapped without a rebuild.</li>
<li><strong>Prioritise long-lived data.</strong> Migrate the most sensitive, longest-lived data first.</li>
<li><strong>Follow the standards.</strong> Track NIST and your national cybersecurity agency&#39;s migration guidance.</li>
</ol>
<h2>The bottom line</h2>
<p>Organisations that prepare now will protect their data and earn a reputation for taking security seriously. In a world where information is power, keeping it secret is the foundation of everything else.</p>
<p><em>Related reading: <a href="https://abhisek-goswami.com/blog/secure-rdp-with-ssl-vpn/">Securing remote desktop with an SSL VPN</a> and <a href="https://abhisek-goswami.com/blog/eu-tech-compliance-gdpr-dsa-ai-act/">Tech compliance in EMEA</a>.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/quantum-cryptography-future-of-cybersecurity/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
<item>
<title>JavaScript asynchronous programming: callbacks, promises and async/await</title>
<link>https://abhisek-goswami.com/blog/javascript-async-callbacks-promises-async-await/</link>
<guid isPermaLink="true">https://abhisek-goswami.com/blog/javascript-async-callbacks-promises-async-await/</guid>
<pubDate>Thu, 03 Dec 2026 03:30:00 GMT</pubDate>
<category>Technology</category>
<category>javascript</category><category>async</category><category>promises</category><category>web-development</category>
<description>How JavaScript does more than one thing at a time without freezing the page, from callbacks to promises to async/await, with a worked example.</description>
<content:encoded><![CDATA[<p><img src="https://abhisek-goswami.com/blog/img/javascript-async-callbacks-promises-async-await.png" alt="Infographic: four ways JavaScript handles waiting: callbacks, promises, async/await and Web Workers"></p><p>JavaScript started in the 1990s as a way to add a little life to static web pages. Today it runs interactive sites, single-page apps, mobile apps through frameworks like React, and servers through Node.js.</p>
<p>One feature makes all of that possible: <strong>asynchronous programming</strong>. This guide explains what it is, the three main ways to write it, and how they relate, with a small example you can run.</p>
<h2>What is asynchronous programming?</h2>
<p>Traditional code runs step by step: start a task, wait for it to finish, then move on. Asynchronous code starts a task and <strong>keeps going</strong> while it runs in the background. When the result arrives, the program picks it up.</p>
<p>That brings three benefits:</p>
<ol>
<li><strong>A better user experience.</strong> The page stays responsive while work happens in the background.</li>
<li><strong>Better performance.</strong> Waiting time (for a network call, a file, a timer) is used for other work.</li>
<li><strong>Scalability.</strong> Servers and real-time apps can handle many users at once.</li>
</ol>
<h3>A practical example</h3>
<p>Picture a weather app. The old way: fetch the data, wait, then update the screen, with a frozen page in between. The asynchronous way: request the data, keep showing what you already have, and update the screen the moment fresh data arrives.</p>
<h2>Four approaches in JavaScript</h2>
<table>
<thead>
<tr>
<th>Approach</th>
<th>What it is</th>
<th>Restaurant analogy</th>
</tr>
</thead>
<tbody><tr>
<td><strong>Callbacks</strong></td>
<td>A function passed to another function, run when a task finishes</td>
<td>The waiter brings your food when it&#39;s ready</td>
</tr>
<tr>
<td><strong>Promises</strong></td>
<td>An object that stands for a future result (or failure)</td>
<td>A receipt that guarantees your meal, even if it takes a while</td>
</tr>
<tr>
<td><strong>async/await</strong></td>
<td>Syntax on top of promises that reads like normal code</td>
<td>You read a magazine and pick up where you were when the food arrives</td>
</tr>
<tr>
<td><strong>Web Workers</strong></td>
<td>Separate threads for heavy work</td>
<td>Assistant chefs in a second kitchen</td>
</tr>
</tbody></table>
<p>Which one to use depends on how complex the work is, how readable the code must be, and whether the job is CPU-heavy (Web Workers) or mostly waiting (the other three). Every modern browser supports async/await, so it&#39;s the usual choice today.</p>
<p>The rest of this guide covers callbacks, promises and async/await.</p>
<h2>Callbacks</h2>
<p>A callback is a function you pass to another function so it can be run later.</p>
<ol>
<li>A function that does something asynchronous accepts a callback as an argument.</li>
<li>It starts the operation (fetching data, waiting for a click).</li>
<li>When the operation finishes, it calls your callback with the result.</li>
</ol>
<p>Callbacks are simple, but they nest badly. Three or four dependent steps quickly turn into the &quot;pyramid&quot; known as <strong>callback hell</strong>. Promises were introduced to fix that.</p>
<h2>Promises</h2>
<p>A promise is an object representing the eventual result of an asynchronous operation. It&#39;s always in one of three states:</p>
<ol>
<li><strong>Pending</strong>: the operation is still running.</li>
<li><strong>Fulfilled</strong>: it succeeded, and the promise holds the result.</li>
<li><strong>Rejected</strong>: it failed, and the promise holds the error.</li>
</ol>
<p>You react to the outcome with <code>.then()</code> for success and <code>.catch()</code> for errors. Compared with callbacks, promises give you:</p>
<ul>
<li><strong>Readability:</strong> flat chains instead of nested pyramids.</li>
<li><strong>Easier error handling:</strong> one <code>.catch()</code> can handle errors from the whole chain.</li>
<li><strong>Sequencing:</strong> chained steps run in a clear order.</li>
</ul>
<p>Promises have drawbacks too. Long chains can still be hard to follow (&quot;promise hell&quot;), and the extra layer takes some getting used to. That led to async/await.</p>
<h2>async/await</h2>
<p>Introduced in ECMAScript 2017, <code>async</code> and <code>await</code> are a cleaner way to write promise-based code:</p>
<ul>
<li><code>async</code> marks a function as asynchronous. It always returns a promise.</li>
<li><code>await</code> pauses <strong>that function</strong> until a promise settles, then gives you its value. The rest of the program keeps running.</li>
</ul>
<p>The result is code that reads top to bottom, like the steps you would describe out loud, with ordinary <code>try</code>/<code>catch</code> for errors.</p>
<h3>How async/await relates to promises</h3>
<p>async/await doesn&#39;t replace promises; it&#39;s built on them.</p>
<ol>
<li><strong>The request:</strong> an <code>async</code> function starts an operation that returns a promise.</li>
<li><strong>The wait:</strong> <code>await</code> pauses the function, not the whole program.</li>
<li><strong>The resolution:</strong> the promise fulfils or rejects.</li>
<li><strong>The continuation:</strong> the function resumes with the value, or jumps to <code>catch</code> with the error.</li>
</ol>
<h2>A worked example: square roots</h2>
<p><strong>1. A promise-based function</strong> (with a one-second delay to simulate slow work):</p>
<pre><code class="language-js">function calculateSquareRoot(number) {
  return new Promise((resolve, reject) =&gt; {
    setTimeout(() =&gt; {
      if (number &gt;= 0) {
        resolve(Math.sqrt(number));
      } else {
        reject(new Error(&quot;Cannot calculate the square root of a negative number&quot;));
      }
    }, 1000);
  });
}
</code></pre>
<p><strong>2. Using it with async/await:</strong></p>
<pre><code class="language-js">async function calculateSquareRootAsync(number) {
  try {
    const result = await calculateSquareRoot(number);
    console.log(&quot;Square root:&quot;, result);
  } catch (error) {
    console.error(&quot;Error:&quot;, error.message);
  }
}

calculateSquareRootAsync(9);   // Square root: 3
calculateSquareRootAsync(-4);  // Error: Cannot calculate the square root of a negative number
</code></pre>
<p><strong>What&#39;s happening:</strong></p>
<ul>
<li><code>calculateSquareRoot</code> creates a promise. Its executor resolves with the square root, or rejects for negative numbers.</li>
<li><code>calculateSquareRootAsync</code> is marked <code>async</code>, so it can use <code>await</code>.</li>
<li><code>await</code> pauses the function until the promise settles. On success the value is logged; on failure, <code>catch</code> handles the error.</li>
</ul>
<h2>Key takeaways</h2>
<ul>
<li>Promises are the foundation; async/await is friendlier syntax on top.</li>
<li><code>async</code> functions always return promises.</li>
<li><code>await</code> pauses only the current function until the promise settles.</li>
<li>Understanding promises makes async/await much easier to use well.</li>
</ul>
<p><strong>Further reading:</strong> <a href="https://developer.mozilla.org/en-US/docs/Learn_web_development/Extensions/Async_JS">Asynchronous JavaScript on MDN</a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise reference</a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function">async function reference</a>.</p>
<p><em>Building an API next? Read <a href="https://abhisek-goswami.com/blog/rest-apis-explained/">REST APIs explained with simple examples</a>.</em></p>
<p><em>Originally published at <a href="https://abhisek-goswami.com/blog/javascript-async-callbacks-promises-async-await/">abhisek-goswami.com</a>.</em></p>]]></content:encoded>
</item>
</channel>
</rss>
