<?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 Usman Shahid on Medium]]></title>
        <description><![CDATA[Stories by Usman Shahid on Medium]]></description>
        <link>https://medium.com/@usmanshahid-49307?source=rss-ea02cbbc8bd0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I2Zl4yBevknjC0F9P_MlFQ@2x.jpeg</url>
            <title>Stories by Usman Shahid on Medium</title>
            <link>https://medium.com/@usmanshahid-49307?source=rss-ea02cbbc8bd0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 12:48:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@usmanshahid-49307/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[Don’t Break the Chain: Preserve Transaction Order with Debezium + Kafka + Postgres]]></title>
            <link>https://usmanshahid-49307.medium.com/dont-break-the-chain-preserve-transaction-order-with-debezium-kafka-postgres-cea915c2ce6a?source=rss-ea02cbbc8bd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/cea915c2ce6a</guid>
            <dc:creator><![CDATA[Usman Shahid]]></dc:creator>
            <pubDate>Tue, 27 May 2025 08:29:13 GMT</pubDate>
            <atom:updated>2025-05-27T08:29:13.444Z</atom:updated>
            <content:encoded><![CDATA[<p>Written in collaboration with <a href="https://medium.com/u/38f488d30ad1">KinzaRaza</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-hSQhVdiaptbD_zL" /></figure><p>A few years ago, building real-time data pipelines felt like chasing smoke. Teams wanted fresh data flowing across systems fast, reliably, and without reinventing the wheel every time.</p><p>That’s when connector-based architectures started gaining momentum. Instead of custom scripts or brittle ETL jobs, engineers leaned into tools like Kafka to stream data and Debezium to capture every change at the source.</p><p>Debezium, sitting quietly alongside PostgreSQL, would watch for data changes, transforming raw database changes into a stream of events. Kafka acted as the lifeline, ferrying those events across services. It felt magical: near-real-time data, decoupled systems, and no more polling.</p><p>As this pattern matured, a new twist on the architecture began to take hold: the <strong>Outbox Pattern</strong>.</p><p>Rather than listening to all changes across every table, developers began writing domain events into a dedicated outbox table, right inside the same transaction as their business logic. Debezium would then pick up these outbox events and push them into Kafka, ensuring that service-to-service communication stayed reliable, consistent, and replayable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1HbfCtK1QBwx01mJ" /></figure><p>But as these systems scaled, another challenge emerged:</p><p><strong>How do you maintain the exact order of transactions, especially when the downstream systems depend on it, or do we really need to maintain it?</strong></p><p>If we peek under the hood of PostgreSQL, we’ll find that it’s surprisingly disciplined when it comes to order. Postgres executes and commits statements in the exact sequence they’re written within a single transaction, and when these transactions are flushed to the WAL (Write-Ahead Log) — the stream that Debezium listens to, that sequence is preserved.</p><p>So, in theory, there’s no problem. Debezium reads from the WAL log in a linear, append-only fashion. That means every insert, update, or delete lands in Kafka topics in exactly the order Postgres recorded them. One transaction at a time. Sequential. Atomic. Reliable.</p><p><strong>Sounds foolproof, right?</strong></p><p>Let’s explore the above architecture with an example in this context. If we go deeper, we would have something like the architecture below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hGib_5r8qSPrxfmG" /></figure><p>But if you’ve worked with Kafka long enough, you know there’s another place where things can quietly go wrong: the topic itself.</p><p><strong>And that’s exactly what we witnessed.</strong></p><p>In one of our pipelines, Debezium was happily capturing changes from PostgreSQL and pushing them into a Kafka topic, which, for performance reasons, had 10 partitions (simplified for the blog). Everything seemed fine. The connector read the transactions in order. Kafka received the events. Consumers processed them.</p><p><strong>But something didn’t add up.</strong></p><p>You see, Kafka only guarantees message order within a single partition, not across multiple ones. That means even if Debezium receives the transactions in the right order, once it starts publishing to different partitions, that order no longer remains preserved.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jdMwhBGXvrKxIQTg" /></figure><p>So two related events, say, an <strong>order_created</strong> followed by an <strong>order_updated</strong>, might land on different partitions, processed by different consumers, and end up out of sync downstream.</p><p>In other words, the <strong>source maintained order</strong>, but the <strong>transport broke it</strong>.</p><p><strong>How did we fix it?</strong></p><p>So we knew — there is a real problem, and it wasn’t just theoretical.</p><p>In distributed systems, small misorderings can lead to big headaches: duplicate processing, stale updates, even data corruption if your consumers rely on strict event sequencing. It became clear that preserving transactional order wasn’t just a nice-to-have — it was essential.</p><p>Naturally, we turned our focus to Debezium. Could it help us? Was there a way to route all statements from a single transaction into the same Kafka partition — and in doing so, preserve the original order as it was written to Postgres?</p><p>We started digging.</p><p>That’s when we came across a useful — but often overlooked — feature in Debezium: <strong>PartitionRouting.</strong></p><p>By default, Debezium uses a generic Kafka partitioning strategy based on the record’s key (which might be an ID, a UUID, or whatever your table defines). But this doesn’t account for transaction boundaries. If multiple events in the same transaction have different keys, they’ll likely be routed to different partitions, which is exactly what breaks the order.</p><p>With PartitionRouting, however, we could change that.</p><p>Debezium allows you to configure a custom partitioning strategy — and that’s where the magic happens. Instead of routing based on the record’s key, we configured Debezium to route all events from the same transaction to the same partition, using the transaction ID as the partitioning key.</p><pre>transforms=PartitionRouting<br>transforms.PartitionRouting.type=io.debezium.transforms.partitions.PartitionRouting<br><br>transforms.PartitionRouting.partition.payload.fields=source.txId<br><br>transforms.PartitionRouting.partition.topic.num=2<br>transforms.PartitionRouting.predicate=allTopic</pre><p>After introducing the change in the Debezium configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B_hJm2UgSM7g6gZW" /></figure><p><strong>Order Matters, and It’s Not Automatic</strong></p><p>In the world of real-time data pipelines, especially those built with <strong>Debezium, PostgreSQL, </strong>and<strong> Kafka</strong>, it’s easy to assume that ordering will “just work” — after all, your database is ordered, your connector is reliable, and Kafka is fast. But as we saw, <strong>assumptions about ordering can quietly break down at scale</strong>.</p><p>From <strong>PostgreSQL’s WAL log</strong> to <strong>Debezium’s change events</strong>, the order is preserved — up to a point. Once Kafka topics introduce multiple partitions, the illusion of order can shatter if related events land in different partitions. For systems where <strong>event order defines correctness</strong>, that can have serious downstream consequences.</p><p>By diving into <strong>Debezium’s PartitionRounting </strong>and routing based on a shared business column (transaction id in the context of this blog), we regained control over that order — ensuring that every statement from the same transaction stayed together, processed in sequence, and reached the consumers as intended.</p><p><strong>Key Takeaways:</strong></p><ul><li>PostgreSQL maintains transactional order, and Debezium captures it faithfully.</li><li>Kafka only guarantees order <strong>within a partition</strong>, not across them.</li><li>Debezium’s PartitionRouting can be used to preserve order — if you route by a consistent field like transaction id.<br>You may need to <strong>extract or promote nested metadata</strong> (e.g. transaction ID) for partitioning to work correctly.</li></ul><p><strong>Final Thoughts</strong></p><p>Building resilient event-driven systems is as much about <strong>understanding boundaries</strong> as it is about connecting components. When the system grows — more services, more partitions, more complexity — small cracks in ordering can lead to big inconsistencies.</p><p>But with careful design, and tools like Debezium and Kafka configured with intent, <strong>you can preserve order where it matters</strong> — and build pipelines that are not just fast, but trustworthy.</p><p>See you in another blog — where we dive even deeper into the world of data. 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cea915c2ce6a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Simple AWS Cross Account Cloudwatch Metric Alerting]]></title>
            <link>https://awstip.com/simple-aws-cross-account-cloudwatch-metric-alerting-e13b418a6131?source=rss-ea02cbbc8bd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e13b418a6131</guid>
            <category><![CDATA[alerting]]></category>
            <category><![CDATA[multi-account]]></category>
            <category><![CDATA[alarm]]></category>
            <category><![CDATA[cloudwatch]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Usman Shahid]]></dc:creator>
            <pubDate>Tue, 08 Nov 2022 15:50:03 GMT</pubDate>
            <atom:updated>2022-11-18T17:46:46.008Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Hello Everyone!</strong> 👋</p><p>In the past few years, We all have started moving towards cloud technologies. This is not only helping us to increase our engineering efficiency but also helping us to manage our resources to avoid unseen incidents.</p><p>One of the challenges on the cloud is alerting and it becomes even more difficult when you are working in multi-account setups, Let’s try to understand this with a simple example;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/744/1*m07FGjenjl3qA4QlHa4kjw.png" /></figure><p>Let’s say you have two databases deployed in two different accounts and you want and you have received a requirement to PLACE some general CloudWatch alerts on the consumption of 80% of the allocated storage space, which means whenever you hit 80% of the allocated or 20% of free-storage-space, the alert should get into an ALARM state, furthermore, you should receive these alerts at one place (maybe slack).</p><p>Isn’t it an interesting problem?</p><p>If I classify this problem, we have two major key points;</p><ol><li><em>We need to place a cloud watch metric. alert on our database.</em></li><li><em>We need to generate an alert on slack whenever our desired threshold is reached i.e ≥80% of the allocated storage.</em></li></ol><p>An easy solution to this problem is to have a dedicated lambda deployed on both accounts responsible to place alerts on the database and another lambda to send messages on slack using SNS connected with our Cloudwatch alert.</p><p>But, is it a scalable solution? What if we want to change our threshold? or notification style? we will need to redeploy lambda across all accounts. which isn’t so much FUN for the engineers.</p><p>Let’s try to understand a simple and better solution;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*odsYY5gTJuUxecVXqgBiyw.png" /></figure><p>In the architecture digram, we have three different AWS account having names Production-0, Production-1 and Production-2. I have added Production-0 for simplification and better understanding while Production-1 or Production-2 can also act as our primary driver account.</p><p>In the other two accounts, we have two RDS instances having name database-1 and database-2 respectively;</p><p><strong>First we will need to setup our Production-0 account with following resources:</strong></p><ul><li><strong>Lambda IAM Role<br></strong>Dedicated IAM Role for our lambda with assume role permission.</li><li><strong>Alarm Assigner Lambda: <br></strong>Which will have a code written in your desired language to assume a cross account role and place metric alarm. In order to calculate the threshold, we can describe the instances on the target account as well.</li></ul><pre><strong>[We should have all the relevant permissions assigned on our lambda-role to have fully functional lambda-function]</strong></pre><ul><li><strong>Centralised Alert Queue:<br></strong>The next step is to deploy a queue using AWS SQS service to receive all the alerts at one place for further processing and actions.</li><li><strong>Alarm Reciever Lambda:<br></strong>The next step to deploy a function which will have a code written in your desired language to recieve an event from our SQS deployed in the step earlir. This lambda can have multiple implementation and distribution strategies like for <strong>High</strong> criticality resources you might need to escalate a phone-call to on-call engineer and for <strong>Low</strong> criticality resources you just need a <strong>Slack</strong> notification.</li></ul><p><strong>The next step is to setup our rest of the accounts with resources:</strong></p><ul><li><strong>Scalable Implementation<br></strong>The implementation from here will replicate itself for all the secondary accounts, which means you can one Terraform for each resource and use that to deploy accross all accounts to expand you coverage. The accounts can be Production-1, Production-2 …. Production-N. <strong>Isn’t it amazing? </strong>😂</li><li><strong>Cross Account IAM Role<br></strong>The first step is to deploy a cross account role with permission to get assumed from the lambda role deployed in primary account with all the privileges matching the permissions describe the resources and put metric alarm on them.</li><li><strong>SNS Topic (Storage Alert Topic)<br></strong>In the next step, we will need to onbaord our dedicated notification topic which will be used to <strong>receive</strong> an event from <strong>cloudwatch</strong> and push that event to our <strong>centralised queue </strong>deployed in the primary account<strong>.</strong></li></ul><pre><strong>[You can subscribe to the queue deployed in the primary account from the secondary account using the ARN of the queue i.e Centralised Alert Queue in our example]</strong></pre><p>In the implementation above, whenever you want to change the thresholds, notification style or distribution strategy, you just need to update your code deployed on lamda in primary account.</p><p>You can use this primary account as the controller of thresholds and distribution of alerts to the engineers.</p><p>I hope you liked this architecture, there can be multiple other distribution and management architectures out there that one can adopt and follow so keep learning… till then.. That’s all folks! 👑</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e13b418a6131" width="1" height="1" alt=""><hr><p><a href="https://awstip.com/simple-aws-cross-account-cloudwatch-metric-alerting-e13b418a6131">Simple AWS Cross Account Cloudwatch Metric Alerting</a> was originally published in <a href="https://awstip.com/">AWS Tip</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Journey to RDS Postgres Encryption-at-Rest with near-to-zero downtime.]]></title>
            <link>https://usmanshahid-49307.medium.com/journey-to-rds-postgres-encryption-at-rest-with-near-to-zero-downtime-da968d656943?source=rss-ea02cbbc8bd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/da968d656943</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <dc:creator><![CDATA[Usman Shahid]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 17:58:46 GMT</pubDate>
            <atom:updated>2022-11-05T05:52:18.257Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zhd2xDLbwdvZLmHbmX_nMg.png" /></figure><p>Hello Folks 👋🏻,</p><p>We’re here again to discuss another interesting topic which is to turn on encryption-at-rest for your new/existing AWS RDS Postgres instance.</p><p>You might be thinking that, Hey isn’t it an easy configuration change from the AWS console or a simple Terraform variable change from False to True? believe me! it’s not that easy for an existing RDS instance.</p><p>So before getting into deeper convo, Let’s start with some background.</p><h3><strong>What is Encryption-at-Rest?</strong></h3><blockquote>Encryption at rest refers to <strong>protecting your data from unauthorized access by encrypting data while stored</strong>.</blockquote><p>So in simple words, in encryption-at-rest, the data stored in the underlying storage gets encrypted from either a customer-managed KMS key or AWS managed KMS key.</p><p>This doesn’t affect/change any behavior on the engine side which means the access to the data from the user will remain the same and will not require any changes from the client side.</p><p>Whenever any particular block of data is accessed or stored in the underlying storage, it gets encrypted/decrypted using the same KMS key that is associated with the RDS instance. This means the encryption actually happens at the storage layer which in AWS is being handled through Elastic Block Volume.</p><h3><strong>How can we enable Encryption-at-Rest for a new instance?</strong></h3><p>If you’re onboarding a new instance, you will need to set enable encryption property under the Encryption block from the console with your desired KMS key.</p><p>I prefer using a customer-managed KMS key because it gives you the flexibility to share with different accounts and can move database snapshots easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhCrnaVsG6pIrCMbj9UrJg.png" /></figure><h3><strong>How can we enable Encryption-at-Rest for an existing instance?</strong></h3><p>So far everything was super easy and straightforward, just a few clicks, and you’re done while for an existing instance AWS doesn’t let you change these configurations on the fly.</p><p>They have some suggested steps:</p><ol><li>Take a downtime on the RDS instance. [~ 2 — 5 mins] 😳</li><li>Take a snapshot of the RDS instance. [~10 mins — 2 hours] 😩</li><li>Encrypt a snapshot with the KMS key. [~10 mins — 2 hours] 😩</li><li>Restore the instance from the encrypted snapshot. [~2–5 mins]😩</li><li>Resume your traffic on the restored instance. [~2–5 mins]😳</li><li>Done. 😩</li></ol><p>These emojis are the actual reactions that I got from the management when I was explaining to them what we got from AWS. 😁</p><p>In any customer-driven company like Careem, this amount of downtime is close to a nightmare. we can barely take downtimes and that too for not more than 5–10 minutes in production.</p><p>So we had to come up with a strategy to reduce this downtime, we looked up at multiple solutions starting from publication/subscription replication, DMS, etc. We can have another story about the findings in a separate blog though in short, we decided to move with DMS.</p><h3><strong>Strategy 1 </strong>💥</h3><p>In the DMS, we decided to keep the approach super simple at the beginning which is as follows;</p><ol><li>Set the following parameter values on the RDS on the parameter group. [~1–2 mins]<br><strong>1a: </strong>rds.logical_replication = 1</li><li>Take the latest snapshot of the instance.</li><li>Encrypt the snapshot with the KMS key.</li><li>Restore the snapshot to a new instance.</li><li>Create a DMS task for all databases under the instance with change data capture CDC configurations.</li><li>Resume the replication by starting the task.</li><li>Switchover traffic to the new instance. [~2–5 mins]</li></ol><p>By following these steps we reduced the downtime on instance from 1–2 hours to just a few minutes.</p><blockquote>It had a major drawback, once we will resume the replication at step 6 it will resume it for the newer records which means you will miss all the records during the snapshot-encryption-restoration period. Which is again a super scary situation to be in for engineers. This strategy is effective and easy if you have a read-heavy database and you can pause writes during the encryption activity while the database is still available for reads.</blockquote><h3>Strategy 2 💥</h3><p>Since we couldn’t afford a downtime on writes as well so we had to come up with a another strategy and we got there using following steps;</p><ol><li>Set the following parameter values on the RDS parameter group. [~1–2 mins]<br><strong>1a: </strong>rds.logical_replication = 1<strong> </strong><br><strong>2b:</strong> session_replication_role = ‘replica’</li><li>Take the latest snapshot of the instance.</li><li>Encrypt the snapshot with the KMS key.</li><li>Restore the snapshot to a new instance.</li><li>Create a DMS task for all databases under the instance with Full Load + CDC after either going with option <strong>5a</strong> or <strong>5b</strong>. <br><strong>5a:<em> </em></strong><em>Truncate your destination database on the target instance.</em><br><strong>5b:<em> </em></strong><em>Take a schema dump of the database, and restore it on the target instance.</em></li><li>Verify the restored database on target and start the DMS task.</li><li>The DMS will perform the Full Load and then move automatically to CDC.</li><li>Switchover traffic to the new instance. [~2–5 mins]</li></ol><blockquote>The steps in this approach are little complicated but worth it. you might have noticed in the step-1, wE have updated an additional parameter which is session_replication_role to ‘replica’ which helps us with full-load. This will ignore foriegn key checks during the execution of DMS task. The DMS task loads data table by table which fails in default postgres settings because of foriegn key constraints.</blockquote><h3>What else?</h3><p>There is another strategy that we didn’t disucss in detail, which is to use logical replication with a <strong><em>publication</em></strong> created on the source and <strong><em>subscription</em></strong> created on encrypted target instance with <strong><em>replica identity full</em></strong> enabled on all the tables, maybe that’s topic for another day!!</p><p>There is no easy way for such activities when you’re working with production databases having 24/7 traffic patterns, huge customer base and very limited slots for downtimes.</p><p>In future, I will our journey for MySQL databases as well which is quite different and really interesting to share as well, till then</p><p>That’s all folks! ;)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=da968d656943" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Step by Step Introduction to Multi-Container Docker Application with React and NodeJs as Frontend…]]></title>
            <link>https://usmanshahid-49307.medium.com/step-by-step-introduction-to-multi-container-docker-application-with-angular-and-nodejs-as-frontend-c10f83b0664c?source=rss-ea02cbbc8bd0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c10f83b0664c</guid>
            <category><![CDATA[node]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[dockerfiles]]></category>
            <category><![CDATA[docker-compose]]></category>
            <dc:creator><![CDATA[Usman Shahid]]></dc:creator>
            <pubDate>Tue, 11 May 2021 13:32:20 GMT</pubDate>
            <atom:updated>2021-05-11T15:29:41.297Z</atom:updated>
            <content:encoded><![CDATA[<p>Step by Step Introduction to Multi-Container Docker Application with React and NodeJs as Frontend and Backend</p><p>Hi Folks! 👋🏻</p><p>We can always relate sometimes how difficult it gets to get started with new techs, so this story will focus on how we can set up a multi-container docker wrapper for your application.</p><p>Since the story is focused on helping beginners, I will try to keep things simple and easy to set up.</p><h4>Source Code:</h4><p>[<a href="https://github.com/m-ata/docker-practise">GIT LINK</a>]<br>It&#39;s always lazy for me to set up a git repository for such sample apps, so this time <a href="https://medium.com/u/75085f71af07">Muhammad Ata</a> helped me out to make this possible… 😁</p><h4>Step 1</h4><p>In order to formulate an example close to real life. I will divide different application layers into docker nodes, where I will use Angular for the front-end and NodeJs for the backend,</p><p>So at first let&#39;s set up a folder structure, As said earlier we are going to divide the front and back end of the application so I am going to have two different folders for that…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*K7rf5gOooG2fMLaqy2t0Nw.png" /></figure><p>The <em>product-crud </em>is the name of my application..</p><h4>Step 2</h4><p>Keep your application backend in the “<em>product-crud-backend”</em> (You can call it anything… am just referring to my naming convention)</p><p>Once you have moved all your backend (NodeJs) code to this then it should look something like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/1*JbY6_oWpW0udOogi8d9JZw.png" /></figure><p>Verify your APIs are working fine in this directory before moving to the next step… 👉🏻</p><h4>Step 3</h4><p>Repeat Step 2 but for “<em>product-crud-frontend” </em>and move your frontend (React) code to this folder… again the naming convention of the folder can be anything..</p><p>Once done your “<em>product-crud-frontend” should look something like this…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*dTr_8TA5bOi2EUxH8qrH-w.png" /></figure><p>We are done with setting up the folder structure to segregate our frontend and backend.. 🙏🏻</p><p>The folder structure should look something like this…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*DiRa5BaAT-v7XQsGtbamCA.png" /></figure><p>Let&#39;s move…</p><h4>Step 4</h4><p>It’s time to make Dockerfile, We are going to make two Dockerfiles to keep things simple,</p><p><strong>[4-A] <br></strong>Create a <strong>Dockerfile</strong> under the <strong>“<em>product-crud-frontend”</em></strong><em> </em>directory and place the following code</p><pre>FROM node:13.12.0-alpine</pre><pre>WORKDIR /crud-app-frontend</pre><pre>COPY package*.json /crud-app-frontend/</pre><pre>RUN npm install</pre><pre>COPY . /crud-app-frontend</pre><pre>CMD [&quot;npm&quot;, &quot;start&quot;]</pre><p><strong>[4-B]<br></strong>Create a <strong>Dockerfile</strong> under the <strong>“<em>product-crud-backend”</em></strong><em> </em>directory and place the following code</p><pre>FROM node:13.12.0-alpine</pre><pre>WORKDIR /crud-app-backend</pre><pre>COPY package*.json /crud-app-backend/</pre><pre>RUN npm install</pre><pre>COPY . /crud-app-backend</pre><pre>CMD [&quot;npm&quot;, &quot;run&quot;, &quot;dev&quot;]</pre><h4>Step 5</h4><p>It’s time to create a “<strong>docker-compose.yml</strong>”<em> </em>which is the most important part of this tutorial. We will link frontend and backend Dockerfile here so is important to create this file in the root directory with the same name “<strong>docker-compose.yml”</strong></p><blockquote>The folder structure should look like this…</blockquote><blockquote>ignore that .gitignore <em>😁</em></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*kccMKDo29PfspC0A5rcX0g.png" /></figure><h4>Step 6</h4><p>Once you have created a “<strong>docker-compose.yml” </strong>place the following code in the file.. the indentation is important so I would recommend installing YML plugin in your IDE (VSCode in my case).</p><pre><strong>version:</strong> &quot;3&quot;</pre><pre><strong>services:</strong></pre><pre><strong>  crud-frontend:<br>     container_name:</strong> product-frontend<br>     <strong>build:</strong> ./product-crud-frontend<br>     <strong>environment:</strong> <br>       NODE_ENV: development      <br>     <strong>ports:</strong><br>        - 8080:3000</pre><pre><strong>  crud-backend:<br>     container_name:</strong> product-backend<br>     <strong>build:</strong> ./product-crud-backend<br>     <strong>environment:</strong><br>       NODE_ENV: development<br>     <strong>ports:<br></strong>        - 8081:3000</pre><pre><strong>  db:<br>     container_name:</strong> mongo_database<br>     <strong>image:</strong> mongo<br>     <strong>ports:</strong><br>        - 27017:27017</pre><p>Let’s walk through our “<strong><em>docker-compose.yml”, </em></strong>take a look at<strong><em> </em></strong>the<strong><em> build </em></strong>keyword we have specified in the <strong>frontend</strong> and <strong>backend</strong> directory path where our <strong>Dockerfile</strong> resides so this way the docker-compose will create a single wrapper with multiple containers...</p><p>We have hosted our database on the node <strong>db </strong>which is using the dedicated image of mongo-db to keep the database container isolated like the rest of all containers…</p><p>What’s next? Nothing we’re good folks! 🤓</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c10f83b0664c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>