<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tushar Jain on Medium]]></title>
        <description><![CDATA[Stories by Tushar Jain on Medium]]></description>
        <link>https://medium.com/@tushar_jain_?source=rss-2152c7535a83------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*yzGi1kXUvnztNzdQYZW-jA.jpeg</url>
            <title>Stories by Tushar Jain on Medium</title>
            <link>https://medium.com/@tushar_jain_?source=rss-2152c7535a83------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 20:59:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tushar_jain_/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Built a WhatsApp AI Agent, and the Hardest Part Wasn’t the AI]]></title>
            <link>https://medium.com/@tushar_jain_/i-built-a-whatsapp-ai-agent-and-the-hardest-part-wasnt-the-ai-808e6dd82185?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/808e6dd82185</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Sun, 15 Nov 2026 06:19:18 GMT</pubDate>
            <atom:updated>2026-11-15T06:19:18.282Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vqNnZuc84LX2W8xXWDpCw.png" /></figure><p><em>I started with a simple appointment-booking flow. What followed changed how I think about conversations, AI decision-making, and building systems that can actually be trusted.</em></p><p><strong>“I don’t want to cancel my appointment.”</strong></p><p>A pretty straightforward message, right?</p><p>Well, the first version of my WhatsApp agent interpreted it as:</p><p><strong>CANCEL_APPOINTMENT — Confidence: 99%.</strong></p><p>The system started the cancellation flow for an appointment the user explicitly wanted to keep.</p><p>It wasn’t an LLM hallucination or a complicated prompt going wrong. It was a problem with how I’d designed the system.</p><p>And that one example captures something I initially underestimated:</p><p><strong>Understanding the words in a message isn’t the same as understanding what someone actually wants.</strong></p><p>Here’s how I got there.</p><h3>I started with a simple idea</h3><p>When I began building a WhatsApp-based appointment-booking agent, I imagined a straightforward conversation.</p><p>The user wants an appointment. The agent asks a few questions, shows available options, collects their selections, and completes the booking.</p><p>I started with Rasa Open Source for intent detection. Booking, rescheduling, cancellation, pricing, and availability each had their own intent.</p><p>The approach seemed reasonable, but it had an assumption I hadn’t questioned.</p><p><strong>I was expecting users to have the conversation in the order I had designed it.</strong></p><p>Real conversations don’t work that way.</p><h3>Users don’t follow your flow. They follow their thoughts.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RHQZRv2yhSgdJr1r3BE7FQ.png" /><figcaption>The flow I designed vs. the chat I actually got.</figcaption></figure><p>For a human, that’s an ordinary conversation. For an application, there’s quite a lot happening.</p><p>The user has mentioned a service, a time, a practitioner, and multiple centres. They’re comparing options, but they haven’t necessarily committed to anything.</p><p>And because this is a multi-centre, multi-service booking system, those details have dependencies.</p><p>A practitioner might work at one centre but not another. A service might be offered at one location but unavailable at another. Even if Arjun works at Whitefield, that doesn’t mean he has an available slot at 10 AM.</p><p>Changing the centre means some earlier availability information may no longer be valid.</p><p>I realised I wasn’t simply collecting booking details.</p><p><strong>I needed to understand how those details evolved throughout the conversation.</strong></p><h3>When my first approach started breaking down</h3><p>The original system treated incoming messages primarily as requests to classify into predefined intents.</p><p>But messages such as “Is he available tomorrow?”, “Same as last time”, or “No, the other one” depend on context.</p><p>The implementation also struggled with short replies, Hinglish, and users correcting themselves.</p><p>I kept adding training examples, adjusting confidence thresholds, and introducing regex rules to catch messages the classifier missed.</p><p>Eventually, those rules were overriding Rasa’s predictions.</p><p>That’s how the cancellation example happened.</p><p>A regex rule looked for combinations of words like “cancel” and “appointment”. It didn’t account for negation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3OLJc67Yt_AvwutglA490w.png" /><figcaption>What users said vs. what my first bot heard</figcaption></figure><p>To be fair, this wasn’t simply Rasa failing. My training dataset was relatively small, and much of the problem came from the custom rules I’d added around it.</p><p>The deeper issue was the design. Every exception seemed to require another condition, and the application was becoming increasingly difficult to reason about.</p><p><strong>I was trying to make people fit into the application instead of making the application understand people.</strong></p><p>That was the turning point.</p><h3>From intent detection to conversation understanding</h3><p>I moved away from the Rasa-first approach and introduced LangChain with Claude Sonnet 5.</p><p>Instead of treating each message as an isolated classification problem, I wanted the system to consider the conversation.</p><p>What is the user trying to achieve? What have they already told us? Are they asking about an option or selecting it? What should happen next?</p><p>But I didn’t want one large model prompt responsible for the entire booking process.</p><p>I started breaking the system into smaller capabilities.</p><p>Finding centres, retrieving services, discovering practitioners, checking availability, retrieving pricing, and handling appointment operations became separate tools with clear responsibilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TY6Wlxv7x7lUTMjtkZNWbQ.png" /><figcaption>One message, four checks. The agent combines tools instead of following a hardcoded flow</figcaption></figure><p>This made the system more flexible but flexibility introduced another problem.</p><h3>Then the agent started taking too long to respond</h3><p>As I continued testing, I noticed that even relatively straightforward questions could take longer than I wanted. And on WhatsApp, where people expect a conversation to keep moving, that delay was noticeable.</p><p>I started questioning whether every incoming message really needed the broader language model to handle all the decision-making.</p><p>Around that time, I came across an article about TypeSafe AI’s <strong>Jev model</strong>.</p><p>Something clicked.</p><p>Several decisions my agent was making were actually quite specific.</p><p>Does the user want to book or reschedule? Which previously offered slot are they referring to? Are they confirming an action or just asking a question? Do they want to speak with a human?</p><p>Did I really need a general-purpose LLM to reason through all these decisions every time?</p><p>That’s when I decided to integrate Jev.</p><p>Jev receives the incoming conversation along with the session memory and answers a predefined set of typed questions, including intent, next action, referenced slot, confirmation, human handoff, and potential red flags.</p><p>The important part is that <strong>Jev doesn’t directly execute actions or get the final say.</strong></p><p>The application evaluates its answers using confidence thresholds that become stricter for higher-risk decisions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be_elmvWitpv42MfWT002w.png" /><figcaption>Simple replies skip the big model; anything new still gets full reasoning</figcaption></figure><p><strong>I deployed Jev into production, and it has improved the agent’s response latency.</strong></p><p>A faster decision is only useful if it’s the right one, so I’m still tuning how much context Jev needs and how efficiently the rest of the processing runs.</p><p><strong>The goal isn’t just a faster AI agent. It’s a faster agent that still understands what the user is trying to do.</strong></p><h3>The hardest part wasn’t remembering information. It was knowing what that information meant.</h3><p>Look at these four messages from the same conversation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fX0dcYN-d2q1ITuiioh90w.png" /><figcaption>Mentioning Arjun isn’t the same as choosing Arjun</figcaption></figure><p>They mention the same practitioner, but they represent different stages of a decision.</p><p>The user might be asking a question, expressing a preference, selecting an option, or explicitly authorising a booking.</p><p>Treating those stages as equivalent could cause the agent to act before the user is ready.</p><p>I started thinking about conversation memory as more than a record of previous messages.</p><p>It needed to represent the user’s current choices, what had been verified, and what was still undecided.</p><p>If the centre changes, the previous availability might be invalid. If the time changes, the earlier confirmation should no longer apply.</p><p><strong><em>Remembering what a user said is not the same as knowing which parts of it are still true.</em></strong></p><p>That became one of the most important principles behind the state management.</p><h3>Knowing what the user wants isn’t permission to act</h3><p>Even when the agent correctly understands the requested service, practitioner, centre, and time, it shouldn’t immediately create an appointment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zdhil34gpw1SlNaOBvJkeQ.png" /><figcaption>A “yes” only counts for the exact details, and a timeout isn’t a failure</figcaption></figure><p>I introduced a confirmation mechanism tied to the specific booking details. It creates a fingerprint of the proposed action, including relevant information such as the patient, service, centre, practitioner, time, and price.</p><p>If a relevant detail changes, the old confirmation becomes invalid.</p><p>This prevents a generic “yes” from authorising a different transaction.</p><p>There was another problem I had to account for.</p><p>What happens if a booking API successfully creates an appointment but the response times out?</p><p>The agent doesn’t know whether the booking succeeded.</p><p><strong>A timeout isn’t proof of failure. It’s an unknown outcome.</strong></p><p>Blindly retrying could create a duplicate appointment.</p><p>So the system attempts to reconcile the outcome against existing appointments instead of immediately repeating the operation.</p><p>This isn’t a complete replacement for server-side idempotency, which remains an area for improvement, but it’s an important distinction.</p><p>The model can help interpret what the user wants. The surrounding system must ensure that the resulting action is valid, authorised, and handled safely.</p><h3>What building this changed in how I think</h3><p>When I started, I imagined an appointment-booking chatbot with a predictable conversation flow.</p><p>Then real conversational patterns challenged that assumption.</p><p>I moved towards contextual understanding, broke the workflow into smaller capabilities, introduced Jev to handle focused decisions, and became more deliberate about state, confirmation, and execution.</p><p>There are still things I’m improving, particularly latency and operational reliability.</p><p>But if I were approaching a similar problem again, I wouldn’t begin by choosing an AI framework.</p><p>I’d first understand how users actually communicate, which information can change during an interaction, and which decisions require verification before the application acts.</p><p>Then I’d decide where AI genuinely helps.</p><p>Because a good agent isn’t just a language model that understands messages or calls APIs.</p><p>It’s a system that can follow a user’s evolving decisions without losing track of what they actually agreed to.</p><p><strong><em>The hardest part wasn’t making the AI capable. It was engineering the judgment, context, and safeguards around that capability.</em></strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=808e6dd82185" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Your Brain Was Never Meant to Be a Search Engine]]></title>
            <link>https://medium.com/@tushar_jain_/your-brain-was-never-meant-to-be-a-search-engine-f8faf0b769dc?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8faf0b769dc</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[psychology]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Thu, 05 Nov 2026 18:27:09 GMT</pubDate>
            <atom:updated>2026-11-05T18:27:09.444Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VRCWigxi38sux9n7pWOyGw.png" /></figure><p><em>We meet people online and offline, have hundreds of conversations, and collect ideas along the way. But what happens when the context of those conversations gets lost?</em></p><h3>We meet people in two ways. Online and offline.</h3><p>Think about the last time you had an interesting conversation with someone.</p><p>Maybe it was a Zoom call with a founder. You discussed a product idea, exchanged thoughts about the market, and agreed to explore something together.</p><p>The conversation was valuable. You wanted to remember what was discussed, what you had agreed upon, and what you needed to do next.</p><p>Fortunately, we now have tools for that.</p><p>Online meeting notetakers can join our calls, record conversations, generate transcripts, summarize discussions, and extract action items. We no longer have to rely entirely on our memory to recall what happened during a meeting.</p><p>Now, imagine meeting the same person a week later.</p><p>This time, you’re sitting across from each other at a coffee shop.</p><p>You discuss how things have progressed since your last conversation. Maybe you talk about a completely different idea. Perhaps you discover a new opportunity, share a personal experience, or make a decision that changes the direction of your earlier discussion.</p><p>Let’s call the first conversation X and the second one Y.</p><p>Together, X and Y represent the complete context of your interactions with this person.</p><p>But here’s the problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-kIaPESF9hpq_Ebvemubg.png" /><figcaption>Two conversations, two tools. Nothing connects X and Y</figcaption></figure><p>They have captured two conversations. They have not captured the continuity between them.</p><h3>The problem isn’t recording conversations. It’s remembering the context.</h3><p>At first, this might sound like a small problem.</p><p>After all, you can always go back and read the transcript of your previous meeting. You can record your in-person conversation. You can even put everything into a single folder.</p><p>But think about what that actually requires.</p><p>You need to remember that a conversation happened. You need to remember where it was recorded. You need to find the right transcript, search through it, and connect what was discussed with the conversation you’re having today.</p><p>In other words, you need to remember enough about something you have forgotten to find the information that helps you remember it.</p><p>That’s a strange problem to have in a world where we have access to so much information.</p><p>And it becomes even more complicated when you meet the same person multiple times.</p><p>Imagine having five conversations with someone over two months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ckk8EbCXufy_kUhB_HKLJg.png" /><figcaption>An idea evolves over five conversations, and the reason for the decision is spread across all of them.</figcaption></figure><p>If you look at each conversation independently, you might understand what happened during that particular meeting. But you could easily miss how the idea evolved, why a particular decision was made, or what led you to that conclusion.</p><p>The meaning isn’t always in a single conversation. Sometimes, it exists between conversations.</p><h3>Our conversations don’t happen in isolated sessions</h3><p>We have become accustomed to thinking about conversations as individual events.</p><p>A meeting has a start time, an end time, a transcript, and a summary. Once the meeting is over, we move on to the next thing.</p><p>But that’s not how human relationships or ideas actually work.</p><ul><li>A conversation with a friend doesn’t end when you leave the coffee shop.</li><li>A discussion with a colleague doesn’t reset when you close Google Meet.</li><li>An idea doesn’t become irrelevant simply because it was discussed three weeks ago.</li></ul><p>Conversations are continuous, even when the tools we use to capture them are not.</p><p>And this is not limited to meetings.</p><p>Think about the different places where information about your life exists today.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hinl6qzLSCDWgV5smfISfw.png" /></figure><p>Each of these contains a small piece of your context. But these pieces rarely come together when you need them.</p><p>You might remember the person but forget the conversation. You might remember the idea but forget who introduced it. You might remember that you made a decision but forget why you made it in the first place.</p><p>And when the context disappears, even information that has been carefully recorded becomes difficult to use.</p><h3>What if we could remember the complete context?</h3><p>This question got me thinking.</p><p>What if we stopped treating every conversation as an independent recording?</p><p>What if the things we captured online, offline, through voice notes, or through our own thoughts could become part of a continuous personal memory?</p><p>Imagine meeting someone today and discussing an idea.</p><p>A few weeks later, you meet them again.</p><p>Instead of starting from scratch, you could ask:</p><ul><li>“What was the idea we discussed last time?”</li><li>“Did we talk about this with anyone else?”</li><li>“What did I promise to follow up on?”</li><li>“How has this idea evolved since our first conversation?”</li></ul><p>And instead of searching through multiple recordings, transcripts, and notes, you could retrieve the relevant context naturally.</p><p>Not just the words.</p><p>The people, the ideas, the decisions, and the connections between them.</p><p>That was the direction I wanted to explore.</p><h3>That’s why I started building Memory AI</h3><p>I didn’t want to build another application that simply records conversations and generates summaries.</p><p>There are already plenty of tools that do that.</p><p>I wanted to explore something different: a personal memory system that helps you capture the things that matter and retrieve them when you need them.</p><p>A place where your voice notes, thoughts, ideas, and conversations don’t have to exist as disconnected pieces of information.</p><p>Memory AI started with this idea.</p><p>Capture something once. Let AI help organize and understand it. And when you need it later, ask about it naturally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZaaBhUzmR98xIsFblDEuw.png" /></figure><p>The goal isn’t to make you remember every single thing.</p><p>It’s to make sure that the things worth remembering don’t disappear just because you forgot where you stored them.</p><p>Because I believe the next interesting evolution of AI isn’t just about making it smarter at answering questions.</p><p>It’s about making it better at understanding the context of our own lives.</p><p>And perhaps, for the first time, giving us a way to remember more without having to think about remembering everything.</p><h3>A small step toward remembering more</h3><p>I don’t think technology should make us spend more time managing information.</p><p>I think it should help us spend more time being present.</p><p>The conversations we have, the ideas we exchange, the promises we make, and the people we meet are all part of our lives. They deserve more than being scattered across recordings, transcripts, and forgotten notes.</p><p>That’s what I’m trying to build with Memory AI.</p><p>Not another place to store things, but a way to bring the things we’ve already captured back into our lives when they matter.</p><p>If this is a problem you’ve experienced too, I’d love for you to be part of what we’re building.</p><p><strong>Memory AI is currently opening its waitlist.</strong></p><p>You can sign up for early access here:</p><p><a href="https://trymemory.app/">Memory AI - Never forget what you promised a client</a></p><p>Because your brain was never meant to be a search engine.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8faf0b769dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to scale beyond CRUD?]]></title>
            <link>https://medium.com/@tushar_jain_/how-to-scale-beyond-crud-0440321acc99?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/0440321acc99</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 21:26:59 GMT</pubDate>
            <atom:updated>2025-08-20T09:40:40.367Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fTVkIssAJ4hMo5di" /></figure><p>In the <a href="https://medium.com/@tushar_jain_/unpacking-the-e-commerce-more-than-a-crud-application-e601e0750b6c">previous article</a>, we saw how CRUD is the skeleton of any E-commerce app, it gets things working, but only at a basic level.</p><p>But real-world platforms like Flipkart or Amazon don’t survive on CRUD alone. They deal with millions of requests per second, flash sales that sell out in seconds, and users spread across the globe.</p><p>So, the real question is: <strong>How do we scale beyond CRUD?</strong></p><p>Let’s break down the essential building blocks that transform a simple CRUD app into a production-ready, scalable system.</p><h3>Load Balancer:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*7M7R2ic0soJ2ygx8Rn_89A.png" /><figcaption>Load balancer</figcaption></figure><p>Haha, the very first one and definitely the most essential. A load balancer is basically the traffic manager for your application. It routes requests from one server to another if a server becomes unresponsive or overloaded. After all, you can’t always predict when a server will hit its limit. If server fails, load balancer doesn’t handle already routed requests.</p><p>Think about large e-commerce sites like Flipkart or Amazon. In just a single second, they process millions (or billions) of requests and transactions. There’s no way a single server could handle all that load. That’s why they scale up by setting up multiple servers and using a load balancer to distribute traffic across them.</p><p>In practice, configuring a load balancer often comes down to writing some configuration files (YAML, JSON, etc.), which define how incoming traffic should be routed, how failures should be detected, and how fallback servers should take over when needed.</p><h3>Caching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*ZCW9VT9z95Y3O83An9McNQ.png" /><figcaption>Caching</figcaption></figure><p>Imagine your store is holding a massive amount of data in the database. Now, let’s say there’s one <strong>popular product</strong> that almost everyone is searching for. Every time a user hits the API, the server has to dig into the DB which is slow and costly.</p><p>But what if we could <strong>cache that product</strong> using Redis (or any other cache handler)? Suddenly, instead of hitting the database, the request fetches it directly from memory it becomes <strong>super fast, almost instant!</strong></p><p>But hey, it’s not always that simple. What if the store manager updates the product details? 🤔 Then comes the big question — <strong>how do we keep our cache fresh?</strong></p><p>There are two common strategies:</p><ol><li><strong>Invalidate on update</strong> — Remove that product ID from Redis when an update event triggers. Next time someone queries it, the system will hit the DB, fetch the latest data, and then re-store it in cache.</li><li><strong>Update the cache directly</strong> — After updating the DB, also update the cached product in Redis (if present in Redis) so both stay in sync.</li></ol><p>At the end of the day, <strong>caching is like a “speed booster” for your app</strong>, giving users quick access to the most frequent or recent searches without requesting your database multiple times.</p><h3>Rate Limiter</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*j7oelJjBc_7zAY2Mi1DqQw.png" /><figcaption>Rate Limiter</figcaption></figure><p>What if someone discovers your backend API and starts <strong>hammering it with requests</strong> every second. Before you know it, your server’s memory fills up, and suddenly it can’t handle legit user requests anymore. That’s a nightmare!</p><p>This is where a <strong>Rate Limiter</strong> jumps in. Think of it like a <strong>sliding window</strong>:</p><ul><li>You define a window size (say 1 minute).</li><li>The limiter tracks how many requests a user makes within that window.</li><li>If the user’s requests go beyond the allowed limit, the extra requests get rejected.</li><li>Once the window resets (after a minute in this case), the user can start making requests again.</li></ul><p>So yeah, a <strong>Rate Limiter is like a traffic cop </strong>for your APIs — it keeps everything moving smoothly and fairly.</p><h3>Searching</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iR0bzaH1mGhJeOIZ" /><figcaption>DB Search</figcaption></figure><p>In the software world, <strong>searching is a whole topic in itself</strong>. There isn’t just <em>one way</em> to search, there are <strong>multiple techniques</strong>, each suited for different needs. Let’s quickly run through a few:</p><ul><li><strong>Keyword-based Search: </strong>Type in a word, and it looks for matches. For example, searching <em>“invit”</em> might suggest <em>“invitation.”</em> Sounds good, right? Well, not always.<br> It works fine for <strong>single word queries</strong>, but what about more complex ones? If you search <em>“Casio watches”</em> it will only return results with that exact phrase. But something like <em>“Casio black watch”</em> may never show up even though it’s clearly relevant.</li><li><strong>Full-Text Search: </strong>Goes deeper by indexing every word in a document, allowing you to match across entire sentences and phrases.</li><li><strong>Fuzzy Search: </strong>Handles typos and spelling mistakes. So, searching <em>“iphon”</em> can still suggest <em>“iPhone.”</em></li><li><strong>Semantic Search: </strong>Goes beyond literal words and looks for <strong>meaning</strong>. If you search <em>“heart attack symptoms,”</em> it could return results about <em>“cardiac arrest”</em> because it understands context.</li><li><strong>Filtered: </strong>Useful in e-commerce, where you search but also filter by price, category, ratings, etc.</li><li><strong>Geospatial Search: </strong>When location matters — like <em>“coffee shops near me.”</em></li></ul><p>…and many more!</p><p>You might have heard about Elastic Search, so what it is and why it is popular when we talk about Elastic Search? ElasticSearch is a <strong>powerful search engine</strong> that bundles all these searching patterns together, letting you pick and use them as per your requirements.</p><p>Honestly, I’ve just brushed the surface here (this topic can easily fill an entire article by itself). If you’d like, I can go full deep-dive in the next article</p><h3>Redis Look Up &amp; Locking Mechanism:</h3><p>When you click on the <strong>Buy Now</strong> button on any e-commerce platform, the system must <strong>instantly verify</strong> whether that product is still available.<br> If this verification takes too long, there’s a risk, while your request is still being processed, another user might successfully purchase the same product. This creates overselling issues and a <strong>bad customer experience</strong>.</p><p>Here’s where <strong>Redis Lookup</strong> comes into play.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*VU2k41dZwJ6RgnFQPMuRsg.png" /><figcaption>Redis Lookup</figcaption></figure><ul><li>Redis stores the <strong>latest inventory data in-memory</strong>, so availability checks are almost <strong>instant</strong> (no round trips to the database).</li><li>This ensures that users always see <strong>real-time stock availability</strong> without delays</li></ul><p>Talking about Locking Mechanism (Concurrency Control), Now, imagine a product with <strong>only 1 unit in stock.</strong></p><p>You click on <strong>Buy Now</strong>. At the same time, another customer tries to purchase it. Without proper handling, both might see the product as available and place orders, a nightmare for inventory management.</p><p>To prevent this, we use a <strong>locking mechanism</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*6Duxd9xYHP6gAKZVv_D7pA.png" /><figcaption>Redis Locking Mechanism</figcaption></figure><ul><li>When you initiate a purchase, the system sets a <strong>lock on that product in Redis</strong> (often using SETNX or Redlock algorithm).</li><li>This lock signals: <em>“This product is already being processed. Wait or try another one.”</em></li><li>Only after your transaction completes (either success or failure), the lock <strong>released</strong>.</li></ul><p>This ensures <strong>atomic operations</strong> meaning only one purchase flow can proceed for that product at a time</p><h3>Horizontal &amp; Vertical Scaling Methods:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*J-1WX22aTqCg9boWDsbAaw.png" /><figcaption>Scaling Types</figcaption></figure><p><strong>Horizontal Scaling: </strong>Think of this as <em>“adding more friends to share the work.”</em> Instead of one server handling all the requests, you bring in multiple servers to serve the high demands. A <strong>load balancer</strong> sits in front and smartly distributes traffic to whichever server has capacity.</p><p>This method is more scalable as there is no limit on how many servers you can set up. Also, if a machine fails, then other servers are running, so there is fault tolerance. <br>At first glance, this method seems more robust, but it requires careful configuration to manage all the distributed components and ensure they communicate properly.</p><p><strong>Vertical Scaling:</strong> It is basically you are adding resources to the existing server, assume you have a AWS t3, 2 vCPU and 4gb RAM, but as days passing your website becomes famous and more users are coming to the website, but your server is overwhelmed by the request of the user so you have to expand the resources like you can expand it to 16 vCPU, 32 gb RAM to handle the overwhelming requests.</p><p>This method is simple to setup as you just have to upgrade the resources and there is no need for updating the code. <br>But here comes the truth, you can’t expand the resource to infinity and there is also a huge cost associated with upgrading the resources.</p><h3>Microservice Architecture:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WmtIrL8SORF9HrhJibGsfA.png" /><figcaption>Microservice Architecture</figcaption></figure><p>Imagine your website has <strong>one service</strong> that gets way more traffic than the rest. You might think, “Let’s just scale the whole application!” But here’s the catch: <strong>scaling everything is expensive and inefficient</strong>, especially when only one part needs more resources.</p><p>This is where <strong>microservice architecture</strong> comes in. Instead of treating your application as a single monolith, you <strong>break it into smaller services</strong>. Each service has its own codebase, resources, and hosting. They communicate with each other through <strong>APIs</strong>.</p><p>In the above case,</p><ul><li>You can <strong>separate the high-traffic service</strong> into its own repo and host it independently.</li><li>If this service needs more resources, you <strong>scale just this part</strong>, leaving the rest of the application untouched.</li></ul><p>Benefits for this case:</p><ul><li>If another service goes down, this high-traffic service keeps running smoothly.</li><li>More <strong>cost-effective and efficient</strong></li></ul><p>Eg. during Flipkart’s <strong>Big Billion Days</strong>, each service experiences massive traffic spikes. Using microservices, they can <strong>analyze which service needs more resources</strong> and scale only that, keeping the rest as it is. Smart, right?</p><p>This sounds good, but you have to think whether using this method in your code makes sense or not? because hosting each service separately costs money, and you need proper API management and inter-service communication. Always evaluate if it makes sense for your project before going with microservice architecture.</p><h3>Kafka:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ko_ug841nSCPgJ1Q" /><figcaption>Kafka</figcaption></figure><p>Kafka is basically an <strong>event streaming platform</strong>. Whenever an update happens, it <strong>streams the data to users in real-time</strong>.</p><p>Think of it like <strong>ordering food</strong>:</p><ul><li>You place an order.</li><li>Kafka receives that event and <strong>broadcasts updates</strong> to everyone associated with it instantly.</li></ul><p>You might think: <em>“Why not just update a database column and show the status?”</em></p><ul><li>Well, if every user had to constantly query the database for updates, the server would be <strong>overwhelmed</strong> by thousands or millions of requests per second.</li><li>With Kafka, users <strong>don’t need to ask the server repeatedly</strong>. They just read updates from the stream as they happen. This <strong>reduces server load</strong> massively.</li></ul><p>Do you know why Kafka is popular?</p><ol><li>Kafka is designed for <strong>very high throughput</strong> (millions of messages/sec) because of its <strong>partitioned log architecture</strong>.</li><li>In most queues, event when consumed the message is gone but in kafka events are stored for days/weeks/months, and consumers can <strong>replay</strong> them anytime (super useful for debugging, reprocessing data, training ML models).</li></ol><h3>DB sharding and replication:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KDPxznGvkG3iEO5ri2oxSw.png" /><figcaption>Database Sharding and Replication</figcaption></figure><p>Imagine an e-commerce giant like <strong>Amazon or Flipkart</strong>. Every second, <strong>millions of users</strong> are browsing products, while some are making purchases at the same time. How does a single database handle <strong>all these read and write requests simultaneously</strong>? That’s where <strong>database management strategies</strong> like replication and sharding come in.</p><p>Database Replication: <br>DB Replication is about <strong>creating copies of your database</strong> to handle specific tasks.</p><ul><li><strong>Read replicas:</strong> Copies that only handle read requests (browsing products).</li><li><strong>Master database:</strong> Handles all write operations (purchases, updates).</li><li>As soon as the master DB is updated, <strong>replicas automatically sync</strong> the changes.</li></ul><p>What’s the use of it?</p><ol><li>Decreased load on main db</li><li>If one replica of the DB fails, then the other DB will serve the purpose.</li></ol><p>Database Sharding:<br>Sharding is about <strong>splitting your database into smaller chunks</strong>, each responsible for a subset of data.</p><ul><li>Each shard handles <strong>read and write operations</strong> for its segment of users or products.</li><li>Sharding is essential for <strong>large datasets</strong>, like in social media or e-commerce platforms.</li><li>Proper <strong>indexing</strong> ensures that requests are routed to the correct shard quickly.</li></ul><p>There is a famous theory about it “Master Slave”</p><p><strong>Master-Slave:</strong> Multiple copies (slaves) of the main database handle read-heavy requests, while the master handles all writes</p><p>Eg. E-commerce platforms (Amazon, Flipkart) checkout writes go to the master, browsing products (read-heavy) go to replicas.</p><p><strong>Master-Master:</strong> Multiple masters handle both read and write operations. Changes are synchronized between masters to maintain consistency.</p><p>This strategy ensures that <strong>the system remains available and performant</strong>, even under massive load.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/770/1*McPsLACVdAhldwRtZ5l9YQ.png" /><figcaption>Deployment Strategiies</figcaption></figure><p>When building software for a large company, you quickly realize that <strong>how you deploy your application</strong> matters just as much as how you build it.</p><ol><li>Recreate Deployment</li></ol><ul><li>Take down the old version completely and make the new version live.</li><li>Simple but <strong>not very efficient</strong>, as there’s downtime during the switch.</li></ul><p>2. Rolling Deployment</p><ul><li>Replace old versions <strong>step by step</strong>, gradually updating all instances.</li><li>Reduces downtime compared to recreate deployment.</li></ul><p>3. Blue Green Deployment</p><ul><li>Blue = old version, Green = new version.</li><li>The old version continues to serve traffic <strong>until the new version is fully built and tested</strong>.</li><li>Once the green version is ready, traffic is shifted seamlessly.</li></ul><p>4. Canary Deployment</p><ul><li>Release the new version to a <strong>small percentage of users first</strong>.</li><li>If it works well, gradually roll it out to everyone.</li><li>Reduces risk by catching potential issues early.</li></ul><p>5. A/B Testing Deployment</p><ul><li>Run <strong>two versions simultaneously</strong> to see which performs better.</li><li>Helps make data-driven decisions about features, design, or performance.</li></ul><p>6. Shadow Deployment</p><ul><li>Run the new version in parallel with the old version.</li><li>All requests to the old version are <strong>duplicated to the new version</strong> for testing performance and correctness without affecting users.</li></ul><p>You might have noticed that when you are making a deployment to your code then you don’t have to do any of these configuration because your service provider is managing all this underhood.</p><p>I’ve primarily used Digital Ocean for hosting, and I wasn’t aware that it actually follows a Blue-Green deployment strategy. Basically what it does is</p><ul><li>It builds a new container for app based on the latest code changes.</li><li>It then performs health checks to ensure the new instance is ready to serve traffic.</li><li>Once the new instance is healthy, the platform switches traffic to it, effectively replacing the old instance.</li><li>The old instance is then gracefully terminated after a grace period, ensuring a smooth transition</li></ul><p>At the end, CRUD gets you started, but scaling keeps you alive.</p><p>Load balancers act as traffic cops, caches make your app lightning fast, rate limiters protect your APIs, Redis locks prevent overselling, and sharding + replication keep your database sane. Add in microservices, Kafka, and smart deployment strategies, and suddenly your CRUD app has evolved into a living, breathing, resilient system.</p><blockquote>Think of CRUD as the skeleton. Scalability techniques are the muscles and nerves. Without them, your app works in theory, but breaks in reality</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0440321acc99" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unpacking the E-commerce — more than a CRUD Application]]></title>
            <link>https://medium.com/@tushar_jain_/unpacking-the-e-commerce-more-than-a-crud-application-e601e0750b6c?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/e601e0750b6c</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ecommerce]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[crud]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Sat, 16 Aug 2025 21:24:21 GMT</pubDate>
            <atom:updated>2025-08-20T09:38:36.335Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unpacking the E-commerce — more than a CRUD Application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*ISsZhXryWYOtXrHuubDMkA.png" /><figcaption>CRUD</figcaption></figure><p>When you first think about an E-commerce application, it usually comes down to a set of basic CRUD operations<br><strong>1.</strong> Showing products to the user based on different categories→ <strong>Get Request </strong><br><strong>2.</strong> Managing inventory through a dashboard → store owners can <strong>create new products (POST)</strong> or <strong>update existing ones (PATCH/PUT)</strong>.<br><strong>3.</strong> Removing the product from the app → <strong>Delete</strong><br><strong>4.</strong> Adding a product to the shopping cart, essentially <strong>creating a new cart entry</strong> or <strong>updating an existing one</strong> for the user.<br>5. Placing an order involves <strong>updating inventory levels</strong> and confirming the purchase, usually a <strong>PATCH/PUT request</strong>.</p><p>Every project usually begins as a simple <strong>CRUD application</strong>. You can break down almost any product into CRUD operations. Take Chat app for example, at its core, it can also be seen as a CRUD app. The main difference is the addition of <strong>websockets</strong>, which allow multiple users to join the same channel while streaming. Even the listing of web series, movies, and shows follows the same CRUD pattern as an E-commerce app does.</p><p>You might wonder if basic CRUD operations can handle everything, but why is there even a need for “overengineering”? The truth is, while CRUD covers the fundamentals, real-world applications demand more. Let’s explore why we need to go beyond the basics.</p><ul><li>Imagine you’ve built an E-commerce app for a single store, complete with an inventory management dashboard.</li><li>Before going online, this store only saw about 50–100 customers a day, and it wasn’t particularly famous.</li><li>After moving online, traffic grows maybe 300–400 customers daily. That’s still manageable with a simple CRUD setup.</li><li>But what happens when the user base steadily rises — 600, 1000, 2000, 5000, and beyond?</li><li>Can the same CRUD system handle this scale effectively?</li><li>The answer is a clear <strong>No</strong>. Consider a product with only 1 unit left in stock. If two users click “Buy” at the exact same time, what happens?</li><li>Both might see a “success” message, or one succeeds while the other gets an error?</li><li>In reality, because the API updates happen almost simultaneously, the system is not configured to handle the conflict properly leading to both orders being recorded.</li><li>The shop owner now sees two confirmed orders but the inventory is showing <strong>-1</strong>, which makes no sense.</li><li>And as user load increases, new issues appear like slower responses, higher chances of downtime, and a poor customer experience that hurts sales. The system also becomes more vulnerable to attacks like <strong>DDoS</strong>.</li><li>Overloaded servers may stop accepting requests, and data syncing issues mean inventory changes aren’t always reflected accurately to users.</li><li>Etccccc…</li></ul><p>This is where the challenge of <strong>handling all these cases</strong> comes in. A CRUD application is just a foundation for building a whole website, and on top of it, we have to build a reliable system and add layers that make it more robust.</p><p>Let&#39;s understand it with the analogy of building a house</p><p>First, you find the right piece of land and lay the foundation — this is your <strong>tech stack selection</strong>. The choice of framework (React, Next.js, etc.) depends on needs like SEO optimization, routing, SSR, or SSG.</p><p>Next comes the <strong>backend language, </strong>which determines how efficiently the server handles CPU usage and request complexity. For example, Go is highly CPU optimized, JavaScript is developer friendly with wide support, and Python is easy to use but not always the most performance-efficient. (I haven’t explored Rust or Ruby much, so I’ll skip them 🙂)</p><p>Then you decide on the <strong>database</strong>, which is like choosing the type of steel rods for your house. Do you need strict schema and ACID compliance (SQL), or more flexibility (NoSQL)? For E-commerce, strict structure and ACID properties are usually preferred.</p><p>With these decisions, you’ve set the location and placed the steel rods. Next come the <strong>bricks and cement</strong>, which represent your database schema defining how data will actually be stored.</p><p>Once the foundation is ready, you start <strong>structuring the rooms,</strong> this is your code architecture and frontend layout. Then you add design and style, just like painting and decorating rooms (CSS).</p><p>After that, you connect electricity, water supply, etc.., this is the <strong>backend integration and functionality wiring</strong> everything together.</p><p>Now, is the house livable at this stage? Technically yes, but it’s barebones. Similar to this, every project begins as a CRUD application — but <strong>CRUD is only the foundation</strong>. Just like a barebones house can’t become a home without furniture, plumbing, and wiring, an E-commerce app can’t succeed without caching, load balancing, rate limiting, search, and other systems that make it resilient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WoWtDKvyxxtebhmln0VtyA.png" /><figcaption>E-Commerce Production ready app</figcaption></figure><h3>What’s Next</h3><p>CRUD is only the <strong>beginning</strong>.</p><p>In the <a href="https://medium.com/@tushar_jain_/how-to-scale-beyond-crud-0440321acc99">next part</a>, we’ll dive into <strong>scaling methods</strong> — how to take your CRUD foundation and make it <strong>production-grade</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e601e0750b6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[House of multiple Containers — Docker Compose]]></title>
            <link>https://medium.com/@tushar_jain_/house-of-multiple-containers-docker-compose-3a647b7860b5?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a647b7860b5</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Fri, 16 Aug 2024 21:50:18 GMT</pubDate>
            <atom:updated>2024-08-16T21:50:18.924Z</atom:updated>
            <content:encoded><![CDATA[<h3>House of multiple Containers — Docker Compose</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CcMtlutf_Zu5_daY.jpeg" /><figcaption>Docker Compose</figcaption></figure><h3>Docker Compose</h3><p>In Dockerfile you have figured out that we are able to run only one container, but what if we want to run multiple containers like one for frontend, another one for the Database, etc?</p><p>So to solve this problem, we came across Docker-Compose. Docker compose is a tool for running multi-container applications on Docker. The main idea behind this is to connect two or more containers with the same network so that containers will be able to communicate with each other. For more reference, <a href="https://docs.docker.com/compose/compose-file/02-model/">refer here</a></p><p>For setting up the Docker compose, you have to create a YAML file to configure your application services. The default path for compose file is compose.yaml/compose.yml or docker-compose.yaml/docker-compose.yml . If both files are present, it will consider the compose.yaml file.</p><p><strong>Top-Level elements in Dockerfile:</strong></p><ol><li><strong>Version top-level element:</strong> It is used only to determine backward compatibility. It has nothing to do with the Schema, it will prefer the latest schema when it is implemented. Ex:- version:&#39;3&#39;</li><li><strong>Services top-level element: </strong>It contains the container’s configuration.</li></ol><blockquote>A Compose file must declare a services top-level element as a map whose keys are string representations of service names, and whose values are service definitions. A service definition contains the configuration that is applied to each service container.</blockquote><p><strong>3. Network top-level element: </strong>Networks are the layers responsible for services to communicate with each other. The top-level networks element lets you configure named networks that can be reused across multiple services. Example:</p><pre>services:<br>  frontend:<br>    image: example/webapp<br>    networks:<br>      - front-tier<br>      - back-tier<br><br>networks:<br>  front-tier:<br>  back-tier:</pre><p><strong>4. Volume top-level element: </strong>Volumes are persistent data stores implemented by the container engine.</p><pre>services:<br>  backend:<br>    image: example/database<br>    volumes:<br>      - db-data:/etc/data<br><br>  backup:<br>    image: backup-service<br>    volumes:<br>      - db-data:/var/lib/backup/data<br><br>volumes:<br>  db-data:</pre><p>In this example, db-data volume is mounted to /var/lib/backup/data and /etc/data container path for the backend and backup respectively.</p><p><strong>5. Configs top-level element: </strong>It allows us to provide the configuration files to your services. Services can only access configs when explicitly granted by a configs attribute within the services top-level element. Example:</p><pre>version: &quot;3&quot;<br>services:<br>  app:<br>    image: web_app<br>    configs:<br>      - app_config<br><br>configs:<br>  app_config:<br>    file: ./config.conf</pre><p><strong>6. Secrets top-level element: </strong>It ensures secure management of sensitive data. This is used to enhance security as the content of secrets is not shown in the logs to expose confidential information during debugging.</p><p><em>Example 1: </em>server-certificate secret is created as &lt;project_name&gt;_server-certificate when the application is deployed,</p><pre>secrets:<br>  server-certificate:<br>    file: ./server.cert</pre><p><em>Example 2:</em> token secret is created as &lt;project_name&gt;_token when the application is deployed</p><pre>secrets:<br>  token:<br>    environment: &quot;OAUTH_TOKEN&quot;</pre><p>If external attribute is set to true then all other attributes except nameare irrelevant.</p><h3>Fragments and Extensions:</h3><p><strong>Fragments: </strong>With fragments, you can make reusable blocks. It is useful when you have common configurations that span multiple services.</p><p>For using fragments, an anchor is defined &amp; sign followed by the alias name. For referencing it, use * sign.</p><pre>volumes:<br>  db-data: &amp;default-volume<br>    driver: default<br>  metrics: *default-volume<br><br># A default-volume anchor is created based on the db-data volume. <br># It is later reused by the alias *default-volume to define the metrics volume.</pre><p><strong>Extensions: </strong>It is also a way to make Compose file more efficient and easier to maintain.</p><p>Use x- as a top-level element to define an extension node. Compose ignores the field that starts with x- .</p><pre>x-custom:<br>  foo:<br>    - bar<br>    - zot<br><br>services:<br>  webapp:<br>    image: example/webapp<br>    x-foo: bar</pre><p>Fragments and Extensions are used collectively for more efficient maintenance of Docker-compose.</p><p><em>Example: </em>The environment variables do not belong to either of the services. Environment variable is lifted into the x-env extension field. The &amp;env YAML anchor is used so both services can reference the extension field’s value as *env.</p><pre>x-env: &amp;env<br>  environment:<br>    - CONFIG_KEY<br>    - EXAMPLE_KEY<br> <br>services:<br>  first:<br>    &lt;&lt;: *env<br>    image: my-image:latest<br>  second:<br>    &lt;&lt;: *env<br>    image: another-image:latest</pre><h3>Difference b/w Docker-compose and Dockerfile:</h3><p>The key difference between the Dockerfile and docker-compose is that the Dockerfile describes how to build Docker images, while docker-compose is used to run multiple Docker containers.</p><p>So the question arises when to use Docker-compose and Dockerfile?🤔</p><p>Dockerfile is mainly used when you are working with only one image but when you are working with multiple containers and you have to set up different containers then Docker-compose is your good-to-go choice.</p><p><em>For Example:</em> When you run only Frontend part of your website then you have the option to use either Dockerfile or docker-compose.</p><p>In the Dockerfile, you provide all the instructions to construct the image for your Frontend part and run the image after building it. But when you are working with the Frontend, Backend, and Database side. You have the option of Dockerfile and Docker-compose but it will be tedious to configure Dockerfile for all apps so we will choose Docker-compose. We can configure all within one file and spin up all the containers using just one command.</p><h3>Sample Setup</h3><p>For setting up the Docker-compose file, I am taking my contest saathi Backend and Frontend Part. The project structure is: /Contest_Saathi contains all the Fronted parts while /Contest-Saathi-Backend part contains backend logic. As I am connecting Frontend, Backend, and Database side. So I will be defining 3 services for that</p><p>Step 1. Make a compose.yaml file in the root directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*9aIC41wCfFvBjy-vld-rfA.png" /></figure><p>Step 2. Design a template showing all the containers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*fBw0Ekr0LfosXyVZ9yjMJQ.png" /></figure><p>Step 3: Implementing the configs of each</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*oLcQG8qhtpyGjLsbG05HMw.png" /></figure><p>In the database container, I have defined the properties image, restart, environment, ports, volumes and networks</p><p><strong>Database Service (database):</strong></p><ul><li><strong><em>Image:</em></strong><em> </em>As you are working with MongoDB, the official image of Mongo is used from Docker Hub.</li><li><strong><em>Restart: </em></strong>Specified the restart property such that whenever the container stops working due to an error it restarts it.</li><li><strong><em>Environment:</em></strong> For configuring the Mongo image, a Username and Password need to be provided in the environment var. You can check the Docker hub about it.</li><li><strong><em>Port: </em></strong>For Mapping of port</li><li><strong><em>Volume:</em></strong> Provided a volume mount to persist the Data<br>It uses a Docker volume named db in the /data/db directory to persist MongoDB data.</li><li><strong><em>Network:</em></strong> Specified the network name i.e. backend network.</li></ul><p><strong>Contest Backend Service :</strong></p><ul><li><strong><em>Depend_on:</em></strong> Determining the sequence of building the Docker-compose. It depends on the backend network which needs to be built before the backend build.</li><li><strong><em>build:</em></strong> It signifies the path of the Dockerfile from where we have to build an image. Either the Image or build command is used. If a build is used, it will search for Dockerfile from where it will build the image. Here, it builds the Docker image from the ./Contest_Saathi directory.</li><li><strong><em>env_file:</em></strong> Specifies the location of the .env file so that It loads environment variables from the .env file in the ./Contest_Saathi directory.</li><li>Port mapping</li><li>Defining networks for configuring it.</li></ul><p><strong>Contest Frontend Service :</strong></p><ul><li><strong><em>Depend_on:</em></strong> contest_backend service will start before building this one container.</li><li><strong><em>build:</em></strong> It builds the Docker image from the ./Contest_Saathi directory.</li><li>Port mapping.</li><li>Network configuration.</li></ul><p>Now you have written your compose.yaml file. So let’s get to know how to run this.</p><p>To run this, you just have to type docker compose up in the root directory where the compose.yaml file is present.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sc_CV11MqiuMxeYc6ADmCA.png" /></figure><p>After running this command in the terminal, all three images are built. Also, all the containers start running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6GdYIqcgvA56zoHfkft2fA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_ylLGY4yZqo-yefFLzAB-w.png" /><figcaption>Docker containers running with logs</figcaption></figure><p>To stop the containers, use docker compose down</p><p>Now, You have successfully learned how to set up the docker-compose file.</p><h3>Conclusion:</h3><p>In this article, you got to learn about Dockerfile and Docker compose files, why we use both the commands and the meaning of different instructions, and set up the Docker file and docker compose file for a sample frontend project and a full stack MERN project.</p><p>Get ready to learn about Kubernetes in my next articles in an interesting way 🤩</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a647b7860b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Art of Crafting Dockerfile]]></title>
            <link>https://medium.com/@tushar_jain_/the-art-of-crafting-dockerfile-af7f9a85c39b?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/af7f9a85c39b</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Thu, 07 Dec 2023 12:26:15 GMT</pubDate>
            <atom:updated>2023-12-09T10:45:31.104Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*6Qhv_c4_9olh6AhA7P2TEw.png" /><figcaption>Dockerfile Decoded</figcaption></figure><p>In my <a href="https://medium.com/@tushar_jain_/exploring-docker-fc45a2744a1c">previous blog</a>, I told you about what Docker is, how it works, and the concept of Docker Images, Volumes, and Containerization in depth with examples and compared it with a VM (Virtual Machine). Also, I have introduced you to different commands used in Docker.</p><blockquote>Docker software helps you to set up the same environment like different package versions, node versions, etc using the containerisation concept.</blockquote><p>It works on the concept of <strong><em>Containerisation</em></strong> i.e. when running any application it spins up a container. Inside the container, it installs various Images based on the required packages and their specific versions.</p><h3><strong>DockerFile</strong></h3><blockquote>A Dockerfile is a text document that contains all the commands or instructions a user could call on the command line in sequence to assemble an image.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/321/1*9drx_HisqWIn0wBrK0q10A.png" /><figcaption>Sample Docker File</figcaption></figure><p>Don’t get amazed by seeing the sample Dockerfile. I will be explaining every command that will be needed for setting up the Dockerfile.</p><h3><strong>Why do we need Dockerfile?</strong>🤔</h3><p>Dockerfile is used to instruct Docker to build a Docker image. Whenever instructions in the Dockerfile are executed, a new layer in the image is formed, and these layers form a stack of layers in the final image.</p><blockquote><strong>According to the documentation</strong>: A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/1*0Qi8paNtwyKEp6iSetJPaw.png" /><figcaption>Dockerfile instruction</figcaption></figure><p>In this example Dockerfile, we are taking the node version 16.14.2 image and setting it up to run a web application using the command npm start.</p><p>I hope that you may get an idea of why we need Dockerfile, if not, don’t worry. Just go through my article, you will surely get to know about it. This is just short information on Dockerfile, read the article completely to get every basic concept of Dockerfile.</p><h3><strong>Format for writing Dockerfile</strong></h3><p>The basic format for writing the Dockerfile is given below</p><pre># Comment<br>INSTRUCTION arguments</pre><ul><li>The instruction is not case-sensitive. However, the convention is for them to be UPPERCASE to distinguish them from arguments more easily.</li><li>A Dockerfile always starts with the FROM command. Only ARGS, Comment, and Parser Directive can appear before the FROM command.</li></ul><p><strong>Note: </strong>For denoting a comment in the Dockerfile, we will use # to denote the comment. Comment lines are removed before the Dockerfile instructions are executed.</p><pre>1st command<br>RUN echo hello \<br># comment<br>world<br><br>2nd Command<br>RUN echo hello \<br>world<br><br>Both the command are identical</pre><p><em>Docker treats lines that begin with </em><strong><em>#</em></strong><em> as a comment unless the line is a valid parser directive.</em></p><pre>Example of Comment:<br>#This is a comment<br><br>For Directive:<br># directive = value</pre><p>A <strong>Parser Directive </strong>is always declared at the start because once a comment, empty line, or builder instruction has been processed, Docker no longer looks for parser directives. Instead, it will be treated as a comment.</p><blockquote>Parser directives are optional, and affect the way in which subsequent lines in a Dockerfile are handled.</blockquote><p>Parser Directive is not case-sensitive but the convention is for them to be in lowercase.</p><p>There are only two directive which is supported i.e. syntax and escape<strong><em>. </em></strong>To know more about it you can<a href="https://docs.docker.com/engine/reference/builder/#parser-directives"> refer here</a>.</p><p><strong>Environment variable:</strong></p><p>It is used in certain instructions as variables to be interpreted by the Dockerfile. It is denoted by $variable_name or ${variable_name}<strong><em>. C</em></strong>urly brackets syntax is used to address issues with variable names with no whitespace.</p><p>Some points regarding Environment Variable</p><ol><li>${variable:-word} indicates that if variable is set then the result will be that value. If the variable is not set then word will be the result.</li><li>${variable:+word}<strong> </strong>indicates that if variable is set then the word will be the result, otherwise the result is the empty string.</li><li>Environment variable substitution will use the same value for each variable throughout the entire instruction.</li></ol><p>Environment variables are supported by the following list of instructions in the Dockerfile: ADD, COPY, ENV, EXPOSE, FROM, FROM and LABEL etc. For more info about it <a href="https://docs.docker.com/engine/reference/builder/#environment-replacement">refer here</a></p><h3>Key Commands in Dockerfile</h3><ol><li><a href="https://docs.docker.com/engine/reference/builder/#from"><strong>FROM </strong></a><strong>:</strong></li></ol><pre>FROM [--platform=&lt;platform&gt;] &lt;image&gt;[:&lt;tag&gt;] [AS &lt;name&gt;]</pre><ul><li>It specifies the base Image for our image.</li><li>Platform and AS flag is optional. Platform will determine the platform where you will run your image and AS flag denotes the name of the build, This name can be used to refer to the image built in this stage.</li><li>Tag refers to the version of the image. If nothing is specified, it will consider it the latest version (:latest).</li></ul><pre>FROM &lt;image&gt;[:&lt;tag&gt;]</pre><p><strong>2. </strong><a href="https://docs.docker.com/engine/reference/builder/#run"><strong>RUN</strong></a><strong>:</strong></p><ul><li>It is used to install and configure packages. RUN command has 2 forms i.e. shell form and exec form.</li></ul><pre>RUN &lt;command&gt;  #Shell form<br>RUN [&quot;executable&quot;, &quot;param&quot;] #exec form</pre><ul><li>It executes any commands on top of the current image and creates a new layer by committing the results and this resulting committed image will be used for the next step.</li></ul><p>The difference between shell and exec forms is about invoking the command shell. In <em>shell exec form, the command shell is invoked</em>, while the <em>exec form is parsed as a JSON array</em> and the command shell is not invoked. If you want to invoke a command shell then execute a shell directly.</p><p>Example: RUN [&quot;sh&quot;, &quot;-c&quot;, &quot;echo $HOME&quot;]</p><p><strong>3.</strong> <a href="https://docs.docker.com/engine/reference/builder/#cmd"><strong>CMD</strong></a><strong>:</strong></p><p>CMD instruction in Dockerfile is used to provide a default command for an existing container.</p><p>It is similar to RUN instruction but the main difference is that RUN executes commands and creates new image layers while CMD sets the command and its parameters to be executed by default after the container is started. If the command is passed in the docker run command then the CMD command is omitted.</p><pre>CMD [&quot;executable&quot;,&quot;param1&quot;,&quot;param2&quot;]  #exec form<br>CMD [&quot;param1&quot;,&quot;param2&quot;]    # default parameters to ENTRYPOINT<br>CMD command param1 param2    #shell form</pre><p>There is a catch in CMD instructions if more than one CMD instruction is found then only the last CMD will take effect.</p><p><strong>4. </strong><a href="https://docs.docker.com/engine/reference/builder/#label"><strong>LABEL</strong></a><strong>:</strong></p><p>It is used in Dockerfile to help organize your Docker Images. These are the key-value pairs used to add metadata to Docker Images.</p><pre>LABEL &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; &lt;key&gt;=&lt;value&gt; ...</pre><p>To view image labels,</p><pre>docker image inspect --format=&#39;{{json .Config.Labels}}&#39; myimage</pre><p><strong>5. </strong><a href="https://docs.docker.com/engine/reference/builder/#expose"><strong>EXPOSE</strong></a><strong>:</strong></p><p>The EXPOSE instruction informs Docker that the container listens on the specified network ports at runtime. We can also specify which protocol to use either TCP or UDP but it is optional. By default, it is TCP protocol.</p><pre>EXPOSE &lt;port&gt; [&lt;port&gt;/&lt;protocol&gt;...]<br><br>Ex: EXPOSE 80/udp</pre><p><strong>6. </strong><a href="https://docs.docker.com/engine/reference/builder/#env"><strong>ENV</strong></a><strong>:</strong></p><pre>ENV &lt;key&gt;=&lt;value&gt; ...<br><br>      OR<br>ENV &lt;key&gt; &lt;value&gt;</pre><p>The ENV instruction sets the environment variable &lt;key&gt; to the value &lt;value&gt;. You can check the ENV variables using docker inspect<strong><em> </em></strong>command and can change them using docker run --env &lt;key&gt;=&lt;value&gt;<strong><em>. </em></strong>For more info, <a href="https://docs.docker.com/engine/reference/builder/#env">refer here</a>.</p><p><strong>7. </strong><a href="https://docs.docker.com/engine/reference/builder/#add"><strong>ADD</strong></a><strong>:</strong></p><p>The ADD instruction copies new files, directories, or remote file URLs from &lt;src&gt; and adds them to the image filesystem at the path &lt;dest&gt;.</p><pre>ADD [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [--checksum=&lt;checksum&gt;] &lt;src&gt;... &lt;dest&gt;<br>ADD [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]</pre><p>The --chown and --chmod property are only supported on Dockerfiles used to build Linux containers, and will not work on Windows containers. These properties are optional.</p><p>The dest is an absolute path, or a path relative to WORKDIR. src can be files or wildcards. To know about various rules ADD obeys, <a href="https://docs.docker.com/engine/reference/builder/#add">refer here</a>.</p><p><strong>8. </strong><a href="https://docs.docker.com/engine/reference/builder/#copy"><strong>COPY</strong></a><strong>:</strong></p><p>The COPY instruction copies new files or directories from &lt;src&gt; and adds them to the filesystem of the container at the path &lt;dest&gt; where dest is the relative path to the WORKDIR or the absolute path and src is the file or wildcard.</p><pre>COPY [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] &lt;src&gt;... &lt;dest&gt;<br>COPY [--chown=&lt;user&gt;:&lt;group&gt;] [--chmod=&lt;perms&gt;] [&quot;&lt;src&gt;&quot;,... &quot;&lt;dest&gt;&quot;]</pre><p>--chownand --chmodproperties are only supported in Dockerfile to build Linux containers, and will not work in Windows containers. These properties are optional. For more, <a href="https://docs.docker.com/engine/reference/builder/#copy">refer here</a>.</p><p><strong>9. </strong><a href="https://docs.docker.com/engine/reference/builder/#entrypoint"><strong>ENTRYPOINT</strong></a><strong>:</strong></p><pre>ENTRYPOINT [&quot;executable&quot;, &quot;param1&quot;, &quot;param2&quot;]  #exec form (preferred)<br>ENTRYPOINT command param1 param2  #shell form</pre><p>It serves as the starting point for a Docker container’s runtime process. When you create a Docker image and instantiate it as a container, the ENTRYPOINT command executes by default.</p><p>If multiple ENTRYPOINT instructions are defined in the Dockerfile, then only the last ENTRYPOINT will have an effect. Also, You can override the ENTRYPOINT setting using docker run --entrypoint flag.</p><p>The main difference between the exec form and the shell form is invoking the shell and the execution part.</p><p>In exec form, the shell is not invoked. Command line arguments to docker run &lt;image&gt;will be appended after all elements in an exec form ENTRYPOINT, and will override all elements specified using CMD.</p><p>While in shell form, shell is invoked and prevents any CMD or run command line arguments from being used, but has the disadvantage that your ENTRYPOINT will be started as a subcommand of /bin/sh -c.</p><p>To know more about it, <a href="https://docs.docker.com/engine/reference/builder/#entrypoint">refer here</a></p><p><strong>10. </strong><a href="https://docs.docker.com/engine/reference/builder/#volume"><strong>VOLUME</strong></a><strong>:</strong></p><p>Volumes are used for persisting the data generated by and used by Docker containers.</p><pre>VOLUME [&quot;/data&quot;]</pre><p>This instruction creates a mount point with the specified name. The value can be a JSON array, a plain string with multiple arguments. For more, refer <a href="https://docs.docker.com/engine/reference/builder/#volume">here</a>.</p><p><strong>11. </strong><a href="https://docs.docker.com/engine/reference/builder/#workdir"><strong>WORKDIR</strong></a><strong>:</strong></p><p>The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile .</p><pre>WORKDIR /path/to/workdir</pre><p>If WORKDIRdoes not exist, then it will be created.</p><p>After going through different instructions, you might be exhausted by seeing only content and code. But don’t worry, I will be showing you how to configure Dockerfile to your real project. So take your laptop out, and proceed with me for the Sample setup of Dockerfile.</p><p>These are the commands which you will mostly encounter while using Docker. If you find something new instruction to you then <a href="https://docs.docker.com/engine/reference/builder/#workdir">refer to this</a> documentation.</p><h3>Sample Setup of Dockerfile:</h3><p>For the Sample Setup of DockerFile, I have been using my Contest Saathi <a href="https://github.com/Tusharjain123/Contest-Saathi">Github Repository</a>.</p><p>The File Structure of the project which I have used is</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/203/1*z8XDP22Nuo9tqAOjd5Iv3w.png" /><figcaption>Structure of my project</figcaption></figure><p>Steps:</p><ol><li>Create a Dockerfile file in the root directory.</li><li>I have used node version 16.14.2, for this project so starting with setting the Base Layer just like this FROM node:16.14.2</li><li>Then copy the content of this image to any folder of your choice(or create one). I have copied the code to the app folder to separate the code from other files. COPY . ./app</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*9TfdALMjFKUGMG0pgsSGHw.png" /><figcaption>Files and Folder inside Docker Container after running the Dockerfile. Inside the app folder, it contains all the codebase</figcaption></figure><p>4. Setting the working directory to the app folder. WORKDIR /app</p><p>5. Our React app is all set to download the node modules and build our app. RUN npm run build &amp;&amp; npm install</p><p>6. Then expose the port to 4000. EXPOSE 4000</p><p>7. Then run an ENTRYPOINT command so that whenever the docker run command is initiated our main script will run ENTRYPOINT [&quot;npm&quot; , &quot;start&quot;]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*76DCpVFDNv4t2Huhx8y3xQ.png" /><figcaption>Sample Dockerfile for this Project</figcaption></figure><p>For running the Dockerfile,</p><ol><li>Build the Dockerfile using</li></ol><pre>docker build -t contest:latest .</pre><p>Here, I have build the Dockerfile using the name contest (you are free to choose any name but remember the naming convention) and tagging with the latest tag. In the end, .represents that the Dockerfile is present in my current directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hniy8sXISkVSbqUcCn1jxg.png" /><figcaption>Under the image section of Docker Desktop, it looks like this</figcaption></figure><p>2. Run the image generated by the build command</p><pre>docker run -p 4000:4000 --name contest_saathi contest</pre><p>It will create the container based on the image given by you in the run command. I have provided the --name flag so that we can identify our container otherwise docker will provide a random name to the container.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6k3nvy45t8yUE5I65jOQQQ.png" /><figcaption>Under the Container section of the Docker desktop, our container is running</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U-xRVs9rK4ntYmwlEpqBwQ.png" /><figcaption>On clicking the container, it will give us various info about our web app instance running on the docker</figcaption></figure><p>You can now check the <a href="http://http//localhost:4000">http://localhost:4000</a> where your project is running successfully.🥳</p><p>Now, you have found it meaningful why we are using different instructions to set up the Dockerfile. But it might be you think if we can run our web app just using Dockerfile then what Docker compose is and why do we use it?</p><p>Let’s figure it out in my next article.🧐🧐</p><p>Also, have a look at this Spacelift article about Dockerfile at <a href="https://spacelift.io/blog/dockerfile">Link</a></p><h3><strong>Conclusion</strong></h3><p>You have learned the concept of Dockerfile and the instructions which are associated with the Dockerfile. You have also set up your sample Dockerfile. You all are set to explore more about the Dockerfile and start using Dockerfile in your daily projects too. If you are stuck at any step in this article, <a href="https://docs.docker.com/engine/reference/builder/">refer to the docs</a> you will understand it quickly.</p><p>It is not over yet. Don’t miss my next article, it will be about Docker-compose files where I will be decoding Docker-compose to you.</p><p>Till then Happy coding, and may your containers sail smoothly across the vast sea of development! 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af7f9a85c39b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring Docker]]></title>
            <link>https://medium.com/@tushar_jain_/exploring-docker-fc45a2744a1c?source=rss-2152c7535a83------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc45a2744a1c</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Tushar Jain]]></dc:creator>
            <pubDate>Sat, 17 Jun 2023 17:21:34 GMT</pubDate>
            <atom:updated>2023-06-17T20:12:14.571Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eTlqcnKw6AStZE7C.png" /></figure><p>Let’s explore Docker</p><h3><strong>Docker</strong></h3><blockquote>Docker is a software platform that allows us to build, test, and deploy applications quickly. Docker is based on the concept of containerization which is packing up all the software needs in a separate container.</blockquote><p>It streamlines the development lifecycle by allowing developers to work in standardized environments using local containers which provide our applications and services. Containers are great for continuous integration and continuous delivery (CI/CD) workflows.</p><p>With the help of Docker, we can quickly deploy and scale our applications in any environment.</p><h4>Docker Desktop</h4><p>It provides a GUI (graphical user interface) that lets you manage your containers, applications, and images directly from your machine without going to the command line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNmWnyoJV2OaPawkppnqqA.png" /><figcaption>Docker desktop opening view</figcaption></figure><p>You will notice that in the left side navigation bar, there are Containers, Images, Volumes, Dev Environments, Learning Center, and Extension options. But the most important among them are <strong>Containers, Volumes, and Images</strong>. Dev Environments is still in development, therefore there may be some bugs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/248/1*0AbKZpkqBCKDSP5XFMDKZw.png" /><figcaption>Side navigation bar</figcaption></figure><p>At first sight, you are probably curious about what containers, images, and volumes in Docker are. So, let’s dig deeper into each term.</p><h4><strong>Containers</strong></h4><blockquote>Docker containers are lightweight, isolated environments that pack our applications and their dependencies for easy deployment and portability. They provide a consistent and reproducible way to run software across different systems, reducing compatibility issues.</blockquote><p>Docker containers are based on Docker technology, which utilizes containerization to encapsulate an application and its dependencies into a self-contained unit.</p><p>We can run a container with the Docker <strong>run</strong> command</p><pre> docker run [OPTIONS] IMAGE [COMMAND] [ARG...]</pre><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*W-WOalAhILClA6VHFdEs1g.png" /><figcaption>Docker run command example</figcaption></figure><p>I used the docker run command to launch an Nginx server. Don’t be frightened by options like -d, --name, and -p; these are the ones I used while executing the nginx image.</p><p>Here, nginx is being pulled from the <strong>Docker hub container image library</strong> as this image is not present in my docker.</p><ul><li>-d is used for detach mode so that we can use our terminal while the container is running parallel.</li><li>--name is used to give the name of the container, if this name is not passed then it will give a random name to our container.</li><li>-p is used to define a port. Here, -p 8080:80 means it maps port 8080 of the host machine to port 80 of the container.</li></ul><p>To check the status of the running container, we use</p><pre>docker container ls<br>or <br>docker ps</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JOYiLrSVMNxrYqxC_XwRJw.png" /><figcaption>All running container is shown here</figcaption></figure><p>To get the info of all containers either active or not, use this command</p><pre>docker container ls -a<br>or <br>docker ps -a</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*da4e_tvkcz_r80TjRc66rw.png" /><figcaption>All active and closed containers are visible here</figcaption></figure><p>For more info about docker containers, refer to <a href="https://docs.docker.com/get-started/what-is-a-container/"><em>Docker container Docs</em></a></p><h4><strong>Images</strong></h4><blockquote>Docker Images can be considered the blueprint of the entire application environment that you create. These images are read-only which means that you can’t make changes and hence, they are immutable. However, on top of these images, when you create containers associated with them, they become writable.</blockquote><p>It contains the definitions of all the libraries, binaries, configuration files, etc. that one would require to run the application.</p><p>Basic syntax</p><pre>docker images [OPTIONS] [REPOSITORY[:TAG]]<br></pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/573/1*Kzaha7TD37JLT-r6k12lNA.png" /><figcaption>docker image command</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*xyoVV3TvCBUNLb2-EkbJ8Q.png" /><figcaption>specifying nginx image</figcaption></figure><p>For more info about docker image, refer to <a href="https://docs.docker.com/engine/reference/commandline/images/"><em>docker image docs</em></a></p><h4><strong>Volumes</strong></h4><p>The purpose of using Docker volumes is to persist data outside the container so it can be backed up or shared.</p><blockquote>Docker volumes are dependent on Docker’s file system and are the <a href="https://docs.docker.com/storage/#good-use-cases-for-volumes">preferred method</a> of persisting data for Docker containers and services.</blockquote><p>When a container is started, Docker loads the read-only image layer, adds a read-write layer on top of the image stack, and mounts volumes onto the container filesystem.</p><p>The basic syntax to create volume is</p><pre>docker volume create [volume_name]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/1*XPWngW4jV6g4yXB5zL1GAw.png" /></figure><p>Simply run this command to obtain information about the active volume.</p><pre>docker volume ls</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*MnhzjaHiOTqS-u0c3_Oyhg.png" /></figure><p>For more info about Docker volumes, you can refer to <a href="https://docs.docker.com/storage/volumes/"><em>Docker volume docs</em></a></p><h4><strong>Dev Environments</strong></h4><blockquote>It will let you create a configurable developer environment with all the code and tools you need to quickly get up and running your project. The Dev Environments feature is currently in Beta phase.</blockquote><p>It uses tools built into code editors that allow Docker to access code mounted in a container rather than on your local host. This isolates the tools, files, and running services on your machine, allowing multiple versions of them to exist side by side.</p><h4><strong>Learning Center</strong></h4><p>It will assist you in getting started with Docker. It includes all the materials you need to learn what Docker is and how to configure it for your projects.</p><h4><strong>Extensions</strong></h4><p>It will let us use third-party tools within Docker Desktop to extend its functionality.</p><p>We can seamlessly connect our favorite development tools to our application development and deployment workflows.</p><p><em>You now understand the concepts of Docker containers, images, and volumes. So, let’s dig a little deeper and question </em><strong><em>why we need to use Docker</em></strong><em>.</em></p><h3><strong>Why Docker?</strong></h3><p>The main question arises “Why do we need Docker?” when any developer can simply access our GitHub code repository and make changes to the code while also seeing it in action?</p><p>The explanation is that it will not work on everyone’s computer in the same way that it does on ours. You may encounter various issues as a result of the different configurations and software versions.</p><p>Assume you’re running PostgreSQL version 15 or node version 19, and the project was based on PostgreSQL version 11 or node version 16, which could cause a variety of dependencies issues.</p><p>It might give some dependency conflicts like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lm0qoH_sq8vamnxXM6dQbg.png" /></figure><p>So, to eradicate this issue, we make use of Docker.</p><p>In docker, all the configuration is set by the owner in a dockerfile or docker-compose file. Then, any developer can run that application without any issues by running the dockerfile or docker-compose file.</p><p>But those who are familiar with Virtual Machines have some doubt in their mind that setting up a virtual machine for the code and configuring a Virtual Machine according to the project configuration achieves the same goal. That’s true but why don’t we use Virtual Machine instead of Docker?</p><p>So, let’s explore this.</p><h4>First, let’s understand Virtual Machine</h4><h4><strong>Virtual Machine</strong></h4><p>A virtual machine is capable of performing tasks such as running applications and programs like a separate computer making them ideal for testing other operating systems like beta releases, creating operating system backups, and running software and applications. Basically, It acts exactly like a computer.</p><h4><strong>How Does a Virtual Machine Work?</strong></h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*-8tAa54CaSrUYNMrGadIeg.png" /><figcaption>How VM works</figcaption></figure><p>Hypervisor is a software that runs on top of the operating system. It also known as a virtual machine monitor (or VMM), is software that creates and runs virtual machines (VMs). A hypervisor allows one host computer to support multiple guest VMs by virtually sharing its resources, such as memory and processing.</p><p>In the above Image, two virtual machines are running on top of the Hypervisor. Each has its own set of configurations for running software under a different operating system, with separate environments.</p><h4>How Does Docker Work?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*J4DSlvIjVj8U3KYHYfi80A.png" /><figcaption>How Docker Works</figcaption></figure><p>Docker Engine is an open-source containerization technology for building and containerizing your applications. It runs on top of the Host Operating System.</p><p>Docker Engine shares the host OS between containers makes them light and increases the boot time. It is considered suitable to run multiple applications over a single OS kernel.</p><p>In the above image, two containers are running above the Docker engine. These two containers have different configurations and dependencies for running an application.</p><p><em>We have seen the working of both Virtual machines and Docker. So, let’s understand what’s the difference between these two.</em></p><h4>Difference between Docker and Virtual Machine</h4><h4>Virtualization</h4><blockquote>Virtualization is a technology that you can use to create virtual representations of servers, storage, networks, and other physical machines.</blockquote><p>Both Docker and Virtual Machine provide isolated environments to run an application. But the way they will provide this isolation is different. Virtual Machine virtualizes both the <a href="https://en.wikipedia.org/wiki/Kernel_(operating_system)">OS kernel</a> and the <a href="https://en.wikipedia.org/wiki/Application_layer#:~:text=An%20application%20layer%20is%20an,IP)%20and%20the%20OSI%20model.">Application layer</a> as they have their own OS running on top of the host OS.</p><p>On the other hand, Docker virtualizes only the application layer and runs on top of the host Operating System.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*EPl9qjzDllrhFUvjowEuIg.png" /><figcaption>Virtualization in Virtual Machine and Docker</figcaption></figure><h4><strong>Security</strong></h4><p>Docker containers are applications that run on top of the host operating system. As a result, if the host OS is vulnerable to security flaws, so are the Docker containers too.</p><p>But in the case of a Virtual Machine, it has its own Kernel and security features. VMs provide a better security model than traditional machines by providing an additional layer of hardware abstraction and isolation, effective external monitoring and recording, and on-demand access. So, it is more secure than the docker container.</p><h4><strong>Performance</strong></h4><p>Docker containers are lightweight and have smaller file sizes. It can be started easily within a few milliseconds.</p><p>But Virtual Machine is more resource intensive, it has to load the entire OS to start. So, it takes a few minutes to run a VM instance.</p><p>Also, Docker leverages the host system’s kernel, resulting in lower overhead(resource requirements and computational burden). This streamlined isolation mechanism allows containers to run with less performance impact compared to the full virtualization approach used by VMs.</p><h4><strong>Portability</strong></h4><p>Here, Portability means the ability to move an application from one host environment to another.</p><p>Docker containers are more portable due to containerization technology’s inherent portability. Docker containers are designed to be platform-agnostic and provide a consistent runtime environment. While portability in a virtual machine (VM) can be a complex process depending on various factors such as the virtualization platform, hardware compatibility, and the operating system involved.</p><h3><strong>Conclusion</strong></h3><p>In conclusion, congratulations on expanding your knowledge about Docker and its various components. Throughout this article, we have delved into the intricacies of Docker and explored its functionalities. Additionally, we have shed light on virtual machines (VMs) and highlighted the differences between Docker and VMs.</p><p>In the next article, I will be giving you a deep understanding of the Dockerfile and docker-compose file.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc45a2744a1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>