<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Abel Ayalew</title>
    <description>The latest articles on DEV Community by Abel Ayalew (@nabroleonx).</description>
    <link>https://dev.to/nabroleonx</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F635787%2F51cb782f-6b14-447e-a02d-a1ae7d3e2a8b.png</url>
      <title>DEV Community: Abel Ayalew</title>
      <link>https://dev.to/nabroleonx</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nabroleonx"/>
    <language>en</language>
    <item>
      <title>Node.js Roadmap: Mastering the Essentials</title>
      <dc:creator>Abel Ayalew</dc:creator>
      <pubDate>Fri, 26 Jan 2024 06:37:59 +0000</pubDate>
      <link>https://dev.to/nabroleonx/nodejs-roadmap-mastering-the-essentials-3o18</link>
      <guid>https://dev.to/nabroleonx/nodejs-roadmap-mastering-the-essentials-3o18</guid>
      <description>&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;p&gt; 1. Prerequisites&lt;br&gt;
 2. Node.js Fundamentals&lt;br&gt;
 3. File System&lt;br&gt;
 4. HTTP Module&lt;br&gt;
 5. Intro to API development&lt;br&gt;
 6. Simple Server with Express.js&lt;br&gt;
 7. Database Integration&lt;br&gt;
 8. Web Sockets&lt;br&gt;
 9. Testing and Debugging&lt;br&gt;
 10. Automation and Deployment&lt;br&gt;
 11. What's Next?&lt;/p&gt;

&lt;p&gt;I'm pretty sure you've seen hundreds, if not thousands, of these out there in the wilderness of the internet. But I'm going to keep it 💯 with you. I won't claim that this is the ultimate roadmap you must follow because what works for one may not work for all. I've put together this roadmap based not only on my experience but also on careful study of how people worldwide approach Node.js through blogs, forums, and videos. Finally, after careful consideration, I've crafted an optimal structure. &lt;em&gt;This blog is mainly aimed at someone starting out on Node.js.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;I am sure it is a no-brainer that you need to have at least basic JavaScript knowledge. You might be wondering, "What does that include?" Well, &lt;em&gt;functions&lt;/em&gt;, &lt;em&gt;callbacks&lt;/em&gt;, &lt;em&gt;objects&lt;/em&gt;, &lt;em&gt;event handlers&lt;/em&gt;, the '&lt;strong&gt;this&lt;/strong&gt;' &lt;em&gt;keyword&lt;/em&gt;, &lt;em&gt;basic expressions&lt;/em&gt;, &lt;em&gt;control statements&lt;/em&gt;, and more fall into this category. You don't need to master everything, but having a basic understanding is crucial. If you find yourself needing a refresher on these topics before delving into Node.js, explore the resources provided below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;📚 &lt;a href="https://eloquentjavascript.net" rel="noopener noreferrer"&gt;Eloquent JavaScript&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;🌐 &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Node.js Fundamentals
&lt;/h2&gt;

&lt;p&gt;Before you go and start doing something, it's always best to learn the basics of the technology. In this case, you should try to understand how node.js works. Try to understand core concepts like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Node.js's non-blocking event-driven I/O&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand how node.js I/O works and how asynchronous operations allow for efficient handling of concurrent tasks.&lt;/li&gt;
&lt;li&gt;Explore the event loop and its role&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Global Object&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Explore global objects in Node.js(i.e. &lt;em&gt;require, process, module, Class:Buffer&lt;/em&gt; etc)&lt;/li&gt;
&lt;li&gt;Understand how global variables and functions are accessible throughout the application.&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;&lt;strong&gt;Node modules&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand CommonJS and ES6 modules and their difference&lt;/li&gt;
&lt;li&gt;Understand how package managers like &lt;strong&gt;npm&lt;/strong&gt; and &lt;strong&gt;yarn&lt;/strong&gt; work. They are designed to streamline the building process, sparing you from manually coding every logic. 🫂&lt;strong&gt;Remember,&lt;a href="https://nodejs.org/en/learn/getting-started/an-introduction-to-the-npm-package-manager" rel="noopener noreferrer"&gt;npm&lt;/a&gt; is your friend.&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/wB9tIg209-8" rel="noopener noreferrer"&gt;Non-blocking I/O and how Node uses it&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/DaU1-XoANig" rel="noopener noreferrer"&gt;NodeJS Architecture - I/O&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/8fPdzhLPhr0?list=PLCiGw8i6Nhvo08rQd9J7e19ToKMCJVKaM" rel="noopener noreferrer"&gt;Node.js Under the Hood&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.golinuxcloud.com/nodejs-global-objects/" rel="noopener noreferrer"&gt;Node.js Global Objects&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/oGO_-DWTmKA" rel="noopener noreferrer"&gt;NPM modules&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  File System
&lt;/h2&gt;

&lt;p&gt;While often underestimated, this is a vital concept that should be understood early on, given its significance. Proper handling of the file system in Node.js is crucial, as it can impact application performance. So, you should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Explore the Node.js File System (fs) module. Learn how to read and write files synchronously and asynchronously.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Learn how to read and write files, create directories, and handle file-related tasks.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nodejs.org/en/learn/manipulating-files/nodejs-file-stats" rel="noopener noreferrer"&gt;Manipulating Files - Node.js Doc&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/hNzRoZti6vI" rel="noopener noreferrer"&gt;Understanding File System by Cododev&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  HTTP Module
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Check out the core HTTP module in Node.js. Understand how to create a basic HTTP server using the HTTP module.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explore handling requests and sending responses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand basic routing using the HTTP module.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nodejs.org/en/guides/anatomy-of-an-http-transaction/" rel="noopener noreferrer"&gt;Anatomy of an HTTP Transaction&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PLyuRouwmQCjnr-rRrhbPrS4YQ0brDQ-14" rel="noopener noreferrer"&gt;Server-Side NodeJS by Steve Griffith&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/3ZAKY-CDKog" rel="noopener noreferrer"&gt;How to Build a Web Server With Node.js by Dave Gray&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Intro to API development
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Expand your understanding of HTTP module capabilities to encompass RESTful API principles.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explore RESTful conventions, including HTTP methods (GET, POST, PUT, DELETE) and resource endpoints.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Apply your knowledge to a hands-on example, by building a basic RESTful API using the Node.js HTTP module.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/_1xa8Bsho6A" rel="noopener noreferrer"&gt;Vanilla Node.js REST API by Traversy Media&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PLyuRouwmQCjnr-rRrhbPrS4YQ0brDQ-14" rel="noopener noreferrer"&gt;Server-Side NodeJS by Steve Griffith&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Simple Server with Express.js
&lt;/h2&gt;

&lt;p&gt;As you progress into building web applications with Node.js, the raw HTTP module can become verbose and lack certain conveniences. This is where &lt;a href="https://expressjs.com/" rel="noopener noreferrer"&gt;Express.js&lt;/a&gt;, &lt;em&gt;a powerful web application framework for Node.js&lt;/em&gt;, comes into play.&lt;/p&gt;

&lt;p&gt;Express simplifies the process of handling &lt;em&gt;HTTP requests&lt;/em&gt;, &lt;em&gt;managing routes&lt;/em&gt;, and &lt;em&gt;dealing with middleware&lt;/em&gt;, making the development of web applications more efficient and enjoyable. Try to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Build a more feature-rich RESTful API by transitioning from a simple HTTP module to Express.js&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement dynamic routing to create more flexible and parameterized routes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Utilize Express middleware for tasks like logging, error handling, and request processing&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Learn how to work with static files and assets&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;❓ &lt;em&gt;Why express you ask&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Well, while Express.js is a popular choice, it's important to note that there are other frameworks and libraries available in the Node.js ecosystem. You might also explore alternatives like Koa.js, Hapi.js, or Fastify, each with its strengths and use cases.&lt;/p&gt;

&lt;p&gt;💡After you get the hang of things, you can experiment with different frameworks to find the tool that aligns best with your preferences and project requirements.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://expressjs.com/en/5x/api.html" rel="noopener noreferrer"&gt;ExpressJS Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://masteringbackend.com/posts/expressjs-5-tutorial-the-ultimate-guide" rel="noopener noreferrer"&gt;ExpressJS Tutorial: The Ultimate Guide&lt;/a&gt; - 🌟&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PL0Zuz27SZ-6P4vnjQ_PJ5iRYsqJkQhtUu" rel="noopener noreferrer"&gt;ExpressJS by Dave Gray&lt;/a&gt; - 🌟&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Database Integration
&lt;/h2&gt;

&lt;p&gt;So far, we've been creating APIs and handling web requests. But in the real world, APIs often need a place to store and retrieve important stuff like user details, authentication info, etc. That's where databases come in.&lt;/p&gt;

&lt;p&gt;Understanding how to integrate and interact with databases in a Node.js environment is a fundamental skill for any backend developer. Whether you're dealing with NoSQL databases like MongoDB or relational databases such as MySQL and PostgreSQL, knowing how to do it properly is essential for effective data management. So, you should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Explore different databases commonly used with Node.js (e.g., MongoDB, MySQL, PostgreSQL)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Learn how to interact with databases using popular Node.js libraries or Object-Relational Mapping(ORM) tools(e.g., &lt;em&gt;mongoose&lt;/em&gt;, &lt;em&gt;sequelize&lt;/em&gt;, &lt;em&gt;typeorm,&lt;/em&gt; etc)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Docs(&lt;a href="https://www.mongodb.com/docs/manual/" rel="noopener noreferrer"&gt;MongoDB&lt;/a&gt;, &lt;a href="https://dev.mysql.com/doc/" rel="noopener noreferrer"&gt;MySQL&lt;/a&gt;, &lt;a href="https://www.postgresql.org/docs/" rel="noopener noreferrer"&gt;PostgreSQL&lt;/a&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=-PdjUx9JZ2E&amp;amp;pp=ygUMbm9kZSBtb25nb2Ri" rel="noopener noreferrer"&gt;Intro to MongoDB&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.mysqltutorial.org/mysql-nodejs/" rel="noopener noreferrer"&gt;MySQL Node.js&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/p-yKR7GusqM" rel="noopener noreferrer"&gt;Getting Started With Sequelize and PostgreSQL&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Web Sockets
&lt;/h2&gt;

&lt;p&gt;In the world of software development, sometimes you need more than just a one-time request to the server. What if you want your app to communicate instantly, like in a chat application? That's why you need to understand web sockets. Web sockets allow for a true two-way connection between a client and a server. To get a better grasp of web sockets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Explore building real-time features effortlessly using Socket.io.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Understand how to handle events and broadcast messages instantly with Web Sockets.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Work on something like a simple chat application as an example.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://socket.io/" rel="noopener noreferrer"&gt;Socket.io Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PL0Zuz27SZ-6NOkbTDxKi7grs_oxJhLu07" rel="noopener noreferrer"&gt;Building a chat app by Dave Gray&lt;/a&gt;🌟&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://beej.us/blog/data/websockets/" rel="noopener noreferrer"&gt;Beej's Guide to WebSockets&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing and Debugging
&lt;/h2&gt;

&lt;p&gt;If you've ever done some coding, you've probably bumped into errors a bunch of times. Knowing how to fix these problems quickly is super important, and that's what debugging is all about. Testing ensures our code behaves as intended, preventing unintentional issues when adding new features or making changes. It's like checking to make sure we don't accidentally disrupt things that were working smoothly before.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Discuss strategies for testing in Node.js e.g. &lt;em&gt;Unit Testing&lt;/em&gt;, &lt;em&gt;Integration Testing&lt;/em&gt;, etc&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Familiarize yourself with testing frameworks (e.g., Jest, Mocha).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Learn basic debugging techniques such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Using Node's built-in debugger&lt;/li&gt;
&lt;li&gt;Command-line debugging&lt;/li&gt;
&lt;li&gt;Chrome DevTools debugging&lt;/li&gt;
&lt;li&gt;Debugging in your code editor(i.e. VsCode)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;❗Keep in mind, Debugging isn't just logging&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://nodejs.org/en/guides/debugging-getting-started/" rel="noopener noreferrer"&gt;Debugging - Getting Started&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/qz68RsESlp8" rel="noopener noreferrer"&gt;How to use VsCode debugger&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://medium.com/backenders-club/nodejs-unit-testing-tutorial-a-comprehensive-guide-85c9734e47b6" rel="noopener noreferrer"&gt;NodeJS Unit Testing Tutorial: A Comprehensive Guide&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/t5sFkGk8GY8" rel="noopener noreferrer"&gt;ExpressJS - Jest &amp;amp; Unit Testing&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Automation and Deployment
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Touch on containerization with Docker.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Explore deployment options (e.g., Heroku, AWS, DigitalOcean).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Consider scaling strategies and important considerations.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Resources:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/JDUB9ZAjaJI" rel="noopener noreferrer"&gt;Deploy NodeJS Apps with Docker&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://youtu.be/X3F3El_yvFg" rel="noopener noreferrer"&gt;Automatic Deployment With Github Actions&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;As I conclude this roadmap, it's crucial to recognize that learning in the world of Node.js is an ongoing process. Here are some key steps to enrich your understanding and become a proficient Node.js developer:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Explore the Docs:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Don't forget that &lt;a href="https://nodejs.org/docs/latest/api/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; is your best friend. The official Node.js documentation is a goldmine of information. Whenever you face a challenge or want to dive deeper, the docs will light your way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;2. Join Communities:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Be an active part of online communities where developers share their experiences and insights. Participate in discussions, ask questions, and contribute your knowledge. Some noteworthy communities include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/t/node"&gt;Node.js on Dev.to&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/node" rel="noopener noreferrer"&gt;Reddit - r/node&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://discordapp.com/invite/vUsrbjd" rel="noopener noreferrer"&gt;Discord - Nodeiflux&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Engage in Open Source:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Jump into open-source projects to grow your skills and work together with other developers. It's a great way to learn, share what you know, and make a difference.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. More Advanced Concepts:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;As you continue your journey, consider exploring more advanced concepts:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication and Authorization&lt;/li&gt;
&lt;li&gt;Security&lt;/li&gt;
&lt;li&gt;Performance&lt;/li&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Clean Architecture&lt;/li&gt;
&lt;li&gt;Caching&lt;/li&gt;
&lt;li&gt;Database Concepts: Explore indexes, transactions, replication, sharding, caching, and database clustering&lt;/li&gt;
&lt;li&gt;Microservices&lt;/li&gt;
&lt;li&gt;Containerization&lt;/li&gt;
&lt;li&gt;CI/CD (Continuous Integration/Continuous Deployment)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;Remember, the path to becoming a seasoned developer involves not only mastering the technology but also actively engaging with the broader developer community. Keep reading, keep coding, and don't hesitate to step into the unknown. The Node.js ecosystem is dynamic, and there's always more to discover.&lt;/p&gt;

&lt;p&gt;Happy coding! 👋&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>backend</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Inside the Database: Tables, Indexing, and Keys</title>
      <dc:creator>Abel Ayalew</dc:creator>
      <pubDate>Thu, 18 Jan 2024 19:23:13 +0000</pubDate>
      <link>https://dev.to/nabroleonx/inside-the-database-tables-indexing-and-keys-46bp</link>
      <guid>https://dev.to/nabroleonx/inside-the-database-tables-indexing-and-keys-46bp</guid>
      <description>&lt;p&gt;That's a pretty long title, huh? 😰 Exploring the ins and outs of a database isn't something we can cover in a quick blog post, but I'll break down the main ideas in a simple way. This way, you can get the basics down and be all set to dive into more advanced stuff on your own.&lt;/p&gt;

&lt;p&gt;For the second part of the "Database Fundamentals" series, I was going to write about Database Indexing, but then I thought there were a couple of things we need to understand before we move on to database indexing concepts.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How do databases store table data?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What are indexes? Do they have a type? How are they stored?&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These and some other questions are what we are going to address in this blog, I will keep it concise bear with me.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do databases store table data?
&lt;/h2&gt;

&lt;p&gt;You might say "On disk, duh! 🤷‍♂️", but there is a bit more detail to it. The tables we see(i.e. rows and columns) to visualize our data are just logical representations. The way databases store the table data is with things called &lt;strong&gt;&lt;em&gt;pages.&lt;/em&gt;&lt;/strong&gt; A page is nothing but a fixed-size memory location and is a unit of information read from or written to disk. The size of a page differs from database to database(i.e. &lt;em&gt;8kb for PostgreSQL, 16kb for MySQL(InnoDB)&lt;/em&gt;). Under the hood, these pages are managed by the underlying storage system.&lt;/p&gt;

&lt;p&gt;Each page can store multiple table rows inside depending on the size of the row. The database doesn't read a single row when we do an &lt;strong&gt;I/O&lt;/strong&gt;. It reads one or more pages and we get lots of rows.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;An I/O is a read request to disk but sometimes it can go to the operating system cache instead of disk.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The cost of &lt;strong&gt;page I/O&lt;/strong&gt; dominates the cost of typical database operations, and DBMSs are optimized to minimize this cost.&lt;/p&gt;

&lt;p&gt;Ok got it, we store the rows in pages, but where do we store the actual table data which we have organized in pages? well, we store it in a heap structure and it is not sorted at all. There is neither a relationship between the rows stored on the same page nor is there any connection between the pages. This holds true across various DBMSs.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In this simplest and most basic type of organization, records are placed in the file in the order in which they are inserted, so new records are inserted at the end of the file. Such an organization is called a heap or pile file. ~ Elmasri&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Inserting a new record into the heap is very efficient. However, traversing the heap is very expensive as it holds lots of data and it involves a linear search through the file page by page. This is why we need to utilize &lt;strong&gt;indexes&lt;/strong&gt; to optimize certain kinds of retrieval operations. The indexes tell us what page in the heap we need to pull.&lt;/p&gt;

&lt;p&gt;💡For more info check&lt;strong&gt; Part III STORAGE AND INDEXING &lt;/strong&gt;from "Database Management Systems" by Raghu Ramakrishnan and Johannes Gehrke.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are indexes?
&lt;/h2&gt;

&lt;p&gt;An index is a data structure that organizes data records on a disk to optimize retrieval operations. Without indexing, DBMS has to iterate through every page until it finds the requested data. Without indexing this would be us 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J5gafQDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1705515444950/ebb1845a-585b-45fb-9e7e-591a09643c00.gif%2520align%3D" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J5gafQDO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_800/https://cdn.hashnode.com/res/hashnode/image/upload/v1705515444950/ebb1845a-585b-45fb-9e7e-591a09643c00.gif%2520align%3D" width="" height=""&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An index makes the query fast⚡. Awesome, now, let's talk about two types of indexes: &lt;strong&gt;clustered&lt;/strong&gt; and &lt;strong&gt;non-clustered&lt;/strong&gt;. There are more types, but today, we'll focus on these two.&lt;/p&gt;

&lt;h3&gt;
  
  
  Clustered Indexes
&lt;/h3&gt;

&lt;p&gt;Sometimes a heap file is organized around a single index, a clustered index. A &lt;strong&gt;clustered index&lt;/strong&gt; is a type of index that physically orders the data in the database table according to the index key. This means the order of the data in the clustered index is the same or close to how the data is stored in the table, which makes it very efficient for range queries. They are also called &lt;a href="https://oracle-base.com/articles/8i/index-organized-tables" rel="noopener noreferrer"&gt;&lt;strong&gt;Index Organized Tables&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt;.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In a clustered index, the index data and the actual row data are not stored separately&lt;/strong&gt;. They are in the &lt;strong&gt;same table&lt;/strong&gt; and the clustered index ensures the table data is sorted physically using the key column of the index. Usually, a &lt;strong&gt;primary key&lt;/strong&gt; is considered unless otherwise specified. &lt;em&gt;We can think of clustered indexes as the dictionary. In a dictionary, the words are sorted by alphabet and the definitions(our data) are located next to the corresponding words(our index).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One thing we mustn't forget is that since the clustered index sorts the rows using an index key, there can only be one clustered index. &lt;strong&gt;Additionally, the choice of the key for the clustered index is crucial, as it directly impacts the physical storage and retrieval efficiency of the table's data.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;MySQL(InnoDB) uses a clustered index, &lt;em&gt;how is this clustered index created?🤔. Well, a clustered index is chosen in this order&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Default Primary Key&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a primary key exists, it's automatically chosen as the clustered index.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unique Non-Null Column&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Without a primary key, any unique, non-null column becomes the clustered index.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Hidden Clustered Index&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If neither is available, InnoDB creates a hidden clustered index on a system column with row IDs.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If unfamiliar with &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/innodb-introduction.html#:~:text=InnoDB%20is%20a%20general%2Dpurpose,clause%20creates%20an%20InnoDB%20table." rel="noopener noreferrer"&gt;&lt;strong&gt;InnoDB&lt;/strong&gt;&lt;/a&gt;, it's a MySQL storage engine known for balancing high reliability and high performance. MySQL offers other engines like ISAM, MyISAM, MEMORY, and more, each with distinct features and use cases. InnoDB is the default one.&lt;/p&gt;

&lt;p&gt;Most MySQL indexes (&lt;code&gt;PRIMARY KEY&lt;/code&gt;, &lt;code&gt;UNIQUE&lt;/code&gt;, &lt;code&gt;INDEX&lt;/code&gt;, and &lt;code&gt;FULLTEXT&lt;/code&gt;) are stored in &lt;a href="https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_b_tree" rel="noopener noreferrer"&gt;B-trees&lt;/a&gt;. &lt;em&gt;B-tree is a self-balancing tree that maintains sorted data and allows searches, insertions, deletions, and sequential access in logarithmic time&lt;/em&gt;. You don't have to worry about how B-trees are implemented as it is abstracted for you but if you are interested, I can write a blog about &lt;strong&gt;B-trees&lt;/strong&gt; and &lt;strong&gt;B+ trees.&lt;/strong&gt; But until then, if you want to see how &lt;strong&gt;B Tree&lt;/strong&gt; and &lt;strong&gt;B+ Tree&lt;/strong&gt; work, check out these resources.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;MIT OpenCourseWare - &lt;a href="https://youtu.be/TOb1tuEZ2X4" rel="noopener noreferrer"&gt;Trees and B-Trees&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B Tree &lt;a href="https://www.cs.usfca.edu/~galles/visualization/BTree.html" rel="noopener noreferrer"&gt;visualizer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;B+ Tree &lt;a href="https://www.cs.usfca.edu/~galles/visualization/BTree.html" rel="noopener noreferrer"&gt;visualizer&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Non-clustered Indexes
&lt;/h3&gt;

&lt;p&gt;A non-clustered index is a type of index that does not affect the physical order of the data in the database table. Instead, it creates a separate data structure, such as a B-tree or a hash table, that stores the index key and a pointer to the corresponding record in the table.&lt;/p&gt;

&lt;p&gt;Non-clustered indexes are like "Indexes" in books, wherein we can check the page number and then use that page number to read the page we want.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fliqs4ebl5j43mxt7d7az.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fliqs4ebl5j43mxt7d7az.png" alt="Book index example" width="500" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So as you can see just like the book indexes and the actual content, &lt;strong&gt;index data&lt;/strong&gt; and &lt;strong&gt;actual table data(heap data)&lt;/strong&gt; are stored separately. Take a look at the next figure&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskljdly8z4dvhtk0okc6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fskljdly8z4dvhtk0okc6.png" alt="Non clustered index example" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In PostgreSQL, all indexes are secondary and stored separately from the table's main data (heap). Unlike clustered indexes, secondary indexes require fetching data from both the index and heap during a typical scan. While offering flexibility for optimizing queries, and supporting multiple columns and indexes per table, they may increase storage, memory, and disk I/O. Balancing these factors is essential for maximizing the benefits of secondary indexes in PostgreSQL.&lt;/p&gt;

&lt;p&gt;As you have seen the way MySQL(InnoDB) and PostgreSQL store their indexes differently and it affects their reads and writes differently. I might write a blog about it in the future.&lt;/p&gt;

&lt;p&gt;If you want to learn more about this, Check out Hussain's video(&lt;a href="https://youtu.be/T9n_-_oLrbM" rel="noopener noreferrer"&gt;&lt;strong&gt;Indexing in PostgreSQL vs MySQL&lt;/strong&gt;&lt;/a&gt;). Don't forget to check out his other videos too as he makes exceptional content.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Before we dive into the world of database indexing, we took a moment to understand how databases store information and explored different types of indexes and how they are stored. If it seems a bit overwhelming, don't worry! Give it another read and check out additional resources for more clarity. We touched on things like primary and secondary keys briefly, but we'll delve into them more in future blogs.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;📆 In the upcoming blog, we'll explore the practical details of using indexes to speed up queries, including different types of scans. Get ready for more insights into Database Indexing! Stay tuned, and everything will become clearer.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Happy reading! Bye for now! 👋&lt;/p&gt;

&lt;p&gt;👀 Always remember, this is just the beginning – a glimpse into the vast world of database intricacies. For deeper insights into database indexing and storage, check the resources below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"Fundamentals of Database Systems" by Elmasri and Navathe.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Database Management Systems" by Raghu Ramakrishnan and Johannes Gehrke.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"SQL Performance Explained" by Markus Winand&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.postgresql.org/docs/" rel="noopener noreferrer"&gt;&lt;strong&gt;PostgreSQL Docs&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PLSE8ODhjZXjaKScG3l0nuOiDTTqpfnWFf" rel="noopener noreferrer"&gt;&lt;strong&gt;CMU Intro to Database Systems - YouTube&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Hussein Nasser - &lt;a href="https://www.youtube.com/playlist?list=PLQnljOFTspQXjD0HOzN7P2tgzu7scWpl2" rel="noopener noreferrer"&gt;&lt;strong&gt;Database Engineering - YouTube&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>database</category>
      <category>backend</category>
      <category>postgres</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Database Transactions</title>
      <dc:creator>Abel Ayalew</dc:creator>
      <pubDate>Mon, 15 Jan 2024 15:09:41 +0000</pubDate>
      <link>https://dev.to/nabroleonx/database-transactions-277g</link>
      <guid>https://dev.to/nabroleonx/database-transactions-277g</guid>
      <description>&lt;p&gt;This blog kicks off a series dedicated to exploring databse fundamentals, one step at a time. Stay tuned for more in this evolving series!&lt;/p&gt;

&lt;p&gt;We often hear the abbreviation ACID usually when we talk about database transactions. By now we all know it stands for &lt;strong&gt;A&lt;/strong&gt;tomicity, &lt;strong&gt;C&lt;/strong&gt;onsistency, &lt;strong&gt;I&lt;/strong&gt;solation, and &lt;strong&gt;D&lt;/strong&gt;urability, but what are they? Even before that what is a database transaction? Why do we need transactions? What happens if we don’t do these transactions properly?&lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Transaction?
&lt;/h3&gt;

&lt;p&gt;According to &lt;code&gt;Fundamentals of Database Systems, Elmasri&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;💡 Transaction is an executing program that forms a logical unit of database processing. A transaction includes one or more database access operations—these can include &lt;em&gt;insertion&lt;/em&gt;, &lt;em&gt;deletion&lt;/em&gt;, &lt;em&gt;modification&lt;/em&gt;, or &lt;em&gt;retrieval&lt;/em&gt; operations.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;A transaction is an atomic unit of work that should either be completed in its entirety or not done at all.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Aha&lt;/strong&gt;💡, so basically a transaction is a sequence of database queries that are treated as one unit of work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;🤔 Why do we have to treat them as one atomic unit though❓&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That’s because a lot of times it's very hard to do what we want to do in a single query. We have to do a series of queries to get things done. Lots of systems use this database transaction concept such as banking, ticket reservation, online purchasing, etc.&lt;/p&gt;

&lt;p&gt;Let’s look at a famous banking example to understand transactions better. Let’s say you want to send &lt;strong&gt;$1000&lt;/strong&gt; to your mom for the holiday(&lt;em&gt;yeah you are a good kid&lt;/em&gt;), you pull up your phone write the amount, and hit &lt;strong&gt;SEND&lt;/strong&gt;. What happens now? let’s look👇.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiqqni5aqvs5z59bqsdwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiqqni5aqvs5z59bqsdwn.png" alt="Database Transaction Example" width="800" height="441"&gt;&lt;/a&gt; If the image isn't clear enough check it &lt;a href="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iqqni5aqvs5z59bqsdwn.png" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are a couple of things we can see from the image above.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Start txn&lt;/code&gt; and &lt;code&gt;Commit txn&lt;/code&gt; statements that mark the transaction boundary(lifespan).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;Transactions are atomic&lt;/em&gt;, if both &lt;code&gt;UPDATE&lt;/code&gt; operations don’t succeed, we roll back the transaction.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;N.B.&lt;/strong&gt; Transactions don’t have to be update/insert operations, we can have read-only transactions.&lt;/p&gt;

&lt;p&gt;Let’s go through each property to understand everything better.&lt;/p&gt;

&lt;h2&gt;
  
  
  Atomicity
&lt;/h2&gt;

&lt;p&gt;We have already established that transaction is atomic, it should be either completed to its entirety or not done at all. The atomicity property requires that we execute a transaction to completion.&lt;/p&gt;

&lt;p&gt;🎗&lt;em&gt;If a transaction fails to complete for some reason for example: disk failure, one of the queries fails, or a system crash, all the changes made with prior queries in the transaction should be undone(rollback).&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the image provided, we aimed to illustrate the importance of atomic transactions. However, consider the repercussions if an atomic transaction isn't ensured.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Imagine this scenario&lt;/strong&gt;: &lt;em&gt;your account was debited $1000, but just then, the database crashed. Inconsistency in data happens. Without transaction support, you'd be at a loss of $1000, and your mom wouldn't receive anything. Fortunately, databases do support transactions.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How would the database tackle these kinds of failures?&lt;/strong&gt; Through a &lt;strong&gt;System Log&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The DBMS ensures recovery from transaction-related failures by maintaining a log. This log records all transaction operations impacting database values and additional transaction details necessary for potential recovery from failures. While this responsibility lies with the system, when developing programs, it's crucial to consider which operations should function as a single unit and construct accurate transaction logic accordingly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bw0h6lhgqp3l66n9uai.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5bw0h6lhgqp3l66n9uai.gif" alt="Consistency" width="480" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Consistency
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Consistency&lt;/strong&gt; is all about taking a database from one consistent state to another. Huh? We came back full circle. Let me explain. All that means is that if a transaction is completely executed from beginning to end without interference from other transactions, it should indeed take our database from one consistent state to another. Doesn’t this pretty much look like Atomicity? Well, that’s because to stay consistent we need Atomicity. However, Consistency guarantees that changes made within a transaction are consistent with database constraints. This includes all rules, constraints, cascades, triggers, etc. If the data gets into an illegal state, the whole transaction fails.&lt;/p&gt;

&lt;p&gt;Let’s go back to our previous example, let’s say you were feeling very generous and you wanted to send your mom $10,000 instead of $1000, but that leaves you with -$3,100. We can’t let that happen now, can we? Balances are supposed to be positive, because of this constraint, consistency will be violated and the transaction will be rolled back.&lt;/p&gt;

&lt;p&gt;Consistency extends beyond data integrity. it also applies to our read operations. Consider a scenario with database replicas: when fetching data from a replica, if changes occur in the main database before those updates reach the replicas, querying data during this interval may yield outdated information. This results in inconsistency within the system.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ioyt5gd00vhljwum2ee.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7ioyt5gd00vhljwum2ee.gif" alt="Isolation" width="480" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolation
&lt;/h2&gt;

&lt;p&gt;💡&lt;em&gt;A transaction should appear as though it is being executed in isolation from other transactions, even though many transactions are executing concurrently. That is, the execution of a transaction should not be interfered with by any other transactions executing concurrently&lt;/em&gt;. ~ &lt;strong&gt;&lt;em&gt;Elmasri&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The other ACID properties(&lt;em&gt;Atomicity&lt;/em&gt;, Consistency, and &lt;em&gt;Durability&lt;/em&gt;) describe the behavior of single transactions but Isolation deals with how a transaction behaves in relation to others.&lt;/p&gt;

&lt;p&gt;In SQL, transactions have a characteristic called &lt;em&gt;isolation level.&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Level 0 Isolation:&lt;/strong&gt; This corresponds to &lt;strong&gt;READ UNCOMMITTED&lt;/strong&gt;. It allows &lt;strong&gt;dirty reads&lt;/strong&gt; (allows reading uncommitted data), making it the least restrictive isolation level.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Level 1 Isolation:&lt;/strong&gt; This corresponds to &lt;strong&gt;READ COMMITTED&lt;/strong&gt;. It addresses the issue of dirty reads by allowing reading only committed data, but data might change between reads(non-repeatable reads).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Level 2 Isolation:&lt;/strong&gt; This corresponds to &lt;strong&gt;REPEATABLE READ&lt;/strong&gt;. It means as long as you are in the same transaction your reads will be the same hence preventing non-repeatable reads but falling victim to new data appearing or existing data disappearing between reads(phantom reads), typically occurring with range queries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Level 3 Isolation (True Isolation):&lt;/strong&gt; This corresponds to &lt;strong&gt;SERIALIZABLE&lt;/strong&gt;. It is the most restrictive, preventing issues like dirty reads, non-repeatable reads, phantom reads, and lost updates. However, &lt;strong&gt;it comes at a cost, it's the slowest&lt;/strong&gt;. Different DBMS offer varied implementations of isolation levels, allowing us to balance performance and consistency based on our application's needs. It's a trade-off between strict isolation and transaction speed.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Isolation Level&lt;/th&gt;
&lt;th&gt;Dirty Read&lt;/th&gt;
&lt;th&gt;Nonrepeatable Read&lt;/th&gt;
&lt;th&gt;Phantom&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;READ UNCOMMITTED&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;READ COMMITTED&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;REPEATABLE READ&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;SERIALIZABLE&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;td&gt;No&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There is more to serializability and isolation so I suggest you check Chapter 21 on &lt;strong&gt;&lt;em&gt;Fundamentals of Database Systems&lt;/em&gt;&lt;/strong&gt; by Elmasri for a more detailed explanation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5kc4w1zybwve34f53kn.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi5kc4w1zybwve34f53kn.gif" alt="Durability" width="480" height="366"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Durability
&lt;/h2&gt;

&lt;p&gt;The changes applied to the database by a committed transaction must persist in the database. These changes must not be lost because of any failure. It has to be persisted in disk which makes the process slow but some databases write to in-memory and create snapshots. An example of such a database system is &lt;strong&gt;REDIS&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;❓ How can we ensure durability(&lt;em&gt;permanence&lt;/em&gt;)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, different databases do this differently. There are different durability techniques WAL, AOF, Async snapshot, etc. However, the most common one is the &lt;strong&gt;Write-Ahead Log(WAL).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When using &lt;strong&gt;WAL&lt;/strong&gt;, DBMS persists in a &lt;em&gt;compressed&lt;/em&gt; version of the changes as WAL. Any changes go to disk first and then write the associated changes to the database file. When a crash happens, we can read all the log data and rebuild the state.&lt;/p&gt;

&lt;p&gt;When a database recovers from failures, it uses different techniques, it might look for half-done transactions and roll them back using the info in the logs or it can roll forward and replay committed transactions that haven’t persisted to disk if there is enough info in the logs.&lt;/p&gt;

&lt;p&gt;One thing that can’t be overlooked here is keeping backups regularly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Alright, we've covered the basics of database transactions and the ACID principles. Think of them like the fellowship of the ring sorry, your data. We talked about how these four characteristics: Atomicity, Consistency, Isolation, and Durability, keep everything in check. From making sure transactions happen as a whole to keeping data consistent. While we often don't see it, the database handles a lot of heavy lifting for us. But hey, when it comes to writing our app logic, it's on us to be smart about it.&lt;/p&gt;

&lt;p&gt;💬 Remember, what we covered here is just the tip of the iceberg. There's a whole world of database intricacies out there. If you wanna learn more about database transactions or databases in general, check the resources below.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;"Fundamentals of Database Systems" by Elmasri and Navathe.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"Database Management Systems" by Raghu Ramakrishnan and Johannes Gehrke.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;"SQL Performance Explained" by Markus Winand&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.postgresql.org/docs/" rel="noopener noreferrer"&gt;PostgreSQL Docs&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PLSE8ODhjZXjaKScG3l0nuOiDTTqpfnWFf" rel="noopener noreferrer"&gt;CMU Intro to Database Systems - YouTube&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>database</category>
      <category>backend</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
