<?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 Khurram Naseem on Medium]]></title>
        <description><![CDATA[Stories by Khurram Naseem on Medium]]></description>
        <link>https://medium.com/@khurram.naseem?source=rss-c76a8300e11c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SovCjKq8_tromoWl.</url>
            <title>Stories by Khurram Naseem on Medium</title>
            <link>https://medium.com/@khurram.naseem?source=rss-c76a8300e11c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 12:59:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khurram.naseem/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[How to setup RDS Replication across AWS accounts]]></title>
            <link>https://medium.com/careem-tech/how-to-setup-rds-replication-across-aws-accounts-408314aff9b8?source=rss-c76a8300e11c------2</link>
            <guid isPermaLink="false">https://medium.com/p/408314aff9b8</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[careem]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Khurram Naseem]]></dc:creator>
            <pubDate>Wed, 31 Jul 2019 09:38:05 GMT</pubDate>
            <atom:updated>2019-07-31T09:55:04.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aJTn85mYMKyJpHWbCGyA3Q.jpeg" /></figure><p>Every day, engineering teams are working tirelessly to solve problems and more often than not, this means choosing between the best of many possible solutions. When we share our approaches to technical problems, we hope to fast track this process for our teams.</p><p>Recently, Careem’s DataOPS team was tasked with the migration of a database from one AWS account to another with minimum downtime. Here you will find the specific steps we took to set up a live RDS MySQL replication across AWS accounts.</p><p>The same approach can also be applied to set up production account data for testing in another AWS account like QA. When you are testing on live data, sensitive information must be scrubbed by adding database triggers on the QA account.</p><blockquote>Note: We have tested this functionality on AWS RDS MySQL 5.7 and it works.</blockquote><p>Let’s suppose you have a database named DB1. For the sake of clarity, the accounts will be referred to as “Account A” and “Account B”.</p><p>Do the following task on On Account A.</p><ul><li>Create one new exclusive VPC Security group to be used in new read replica. Let&#39;s name it <strong>sg_share_RDS</strong>.</li><li>On “DB1”, run following to make sure binlog files there for at least 24 hours.</li></ul><pre>call mysql.rds_set_configuration(‘binlog retention hours’,24);</pre><ul><li>Create new RDS Subnet Group, with at least two public subnets attached to this subnet group, let’s name it “share_rds_subnet”.</li><li>Create new Read Replica from database “DB1” with port 3316(or any nondefault port i.e. 3306).</li><li>Set Public access to ‘Yes’ and assign Subnet Group “share_rds_subnet” to Read Replica. Also, enable auto backup on this new read replica.</li><li>Assign security group <strong>sg_share_RDS</strong> to newly created read replica &amp; Allow port 3316 to your VPN Security group to make a connection to this read replica.</li></ul><p>Lock every database user in the new read replica, after switch off (read_only=0) in read replica parameter group, we prefer you also have exclusive DB parameter group for newly created read replica. After locking down all users, create one database user that is exclusively used for replication with a tough password. For example</p><pre>GRANT REPLICATION SLAVE ON *.* TO &lt;your_user&gt;@&#39;%&#39; IDENTIFIED BY &lt;your_password&gt;;</pre><p>Run below command</p><pre>SHOW SLAVE STATUS; </pre><p>And check <em>seconds_behind_master</em> must be <strong>zero</strong>. on a newly created read replica. Make sure the newly create read replica is ready and fully synced with the master. Now do the following steps.</p><p>Stop replication on read replica by calling</p><pre>CALL mysql.rds_stop_replication().</pre><ul><li>Run following command on stop read replica and save values of (<em>Master_Log_File</em> , <em>Read_Master_Log_Pos</em>) to use it later.</li></ul><pre>SHOW MASTER STATUS;</pre><ul><li>If you are on Mac run <em>dig</em> &lt;your stop read replica endpoint&gt; note down the public IP address.</li><li>Take a snapshot of a read replica in account “A” and share snapshot to other AWS account “B” from AWS console.</li><li>After share snapshot restores RDS snapshot in AWS account (“B”) make sure you also have designated security group and subnet group (with at least two public subnets) on the target AWS account.</li><li>Once a snapshot is restored and available, connect to it and run the following commands. Now run <em>dig</em> &lt;newly created RDS endpoint in account “B”&gt;</li></ul><p>Get the public IP address of newly created RDS in account “B” and allow this IP in account “A” ( source DB ) security group to connect on the port which you defined for your read replica. This means only this IP (from the account “B”) can connect to source DB in account “A”.</p><p>Now run following in your target DB in account “B”.</p><pre>CALL mysql.rds_set_external_master(&lt;Public IP Address of stop Read Replica&gt;, &lt;port of read replica&gt;, &lt;username&gt; , &lt;password&gt; , Master_Log_File,Read_Master_Log_Pos, 1);</pre><pre>CALL mysql.rds_start_replication();</pre><p>Now run following command</p><pre>SHOW SLAVE STATUS; </pre><p>on newly created DB in the account “B” and check if its successfully connect to its master database (The read replica on AWS account “A”).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=408314aff9b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/careem-tech/how-to-setup-rds-replication-across-aws-accounts-408314aff9b8">How to setup RDS Replication across AWS accounts</a> was originally published in <a href="https://medium.com/careem-tech">Tech @ Careem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Break the Monolithic Database]]></title>
            <link>https://medium.com/careem-tech/from-monolithic-to-microservices-database-bdf7094d8457?source=rss-c76a8300e11c------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf7094d8457</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[monolith]]></category>
            <dc:creator><![CDATA[Khurram Naseem]]></dc:creator>
            <pubDate>Wed, 22 May 2019 12:25:51 GMT</pubDate>
            <atom:updated>2019-05-23T09:59:26.684Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T62rTMntSJ2pDoLHPN8B5w.jpeg" /></figure><p>Monolithic applications are increasingly being replaced with smaller, more easily maintainable, components or services that communicate with each other to accomplish the same task in a more efficient manner.</p><p>As services are separated from each other, it becomes easier to identify distinct services that are highly utilized and scale those services independently of the whole application.</p><p>Storing data from different domains in a single database has an additional side effect that should not be underestimated. It creates dependencies between different services/domains on a DB schema level. A breaking change on the schema level - e.g. changing the data format of a column — will have a ripple effect through the whole system, ultimately requiring a synchronous change and production deployment of all dependent subsystems. Finding these subsystems, however, is almost impossible as the database often doesn’t provide a reliable way to track those dependencies. Again, this significantly impacts the new feature development as it makes broader and high quality refactoring impossible.</p><p><strong>Data isolation within the existing database</strong></p><p>There is actually a way to approach the split safely using only master-slave replication. The idea is to split/isolate the data within the originating database itself (Main DB). This can be achieved by restricting the MySQL database users.</p><p>For example, the Services “A” data had to be split out of Main DB. So a Services “A” DB user was created and this DB user was restricted to read/write only to the Services “A” data tables. Similarly, all other DB users (one by one) had their access to the Services “A” data tables denied.</p><p>This is a long process that includes extensive monitoring for system abnormalities, because when a DB user (e.g. Services “B” user or Services “C” user) has the access cut, then the service that is using this user might suffer from lack of privileges in case it directly or indirectly (though joins) uses Services “A” tables.</p><p>If abnormalities are detected the user should have their access immediately restored. The process, however, helps with identifying and fixing of rogue services which directly use the Services “A” data tables. Needless to say, the service that is going to have its user access cut from Services “A” tables should have it’s code base thoroughly examined prior to the exercise. In summary, the process will be:</p><ol><li>List all database users.</li><li>Identify the user that with high confidence doesn’t use directly the Services “A” tables</li><li>Cut the access to Services “A” tables to that user.</li><li>Carefully monitor the system for abnormalities.</li><li>If an abnormality is found immediately restore the DB user access, investigate and fix the reason and go to step 3.</li><li>Successfully eliminated the access of the selected user to the Services “A” tables. Go to step 2. for the next user until all users except the</li><li>Services “A” user has their access denied.</li></ol><p>In the end, other users have their access to Services “A” tables cut, we can safely say that the Services “A” data is now <strong>private </strong>to the Services “A”. In other words, even though the data is still residing in the Main DB we have the process of extracting a microservice completed. The next logical step, of course, is to migrate this data to a new database i.e. reap the benefits of having a microservice by changing its data storage. This is now easy, the process is the following:</p><p>1, Create a Main DB read replica (this will be the new master database for microservices).<br>2. Wait for zero replica lag i.e. all data has been replicated.<br>3. Create read/write user in the replica exclusive for the new service<br>4. Reconfigure all DB reads to go to the new read replica. <br>5. Stop the new Services “A” i.e. all writes to the old DB.<br>6. Reconfigure all writes to go to the new read replica.<br>7. Wait for zero DB lag. Promote the read replica as a new master node.<br>8. Start the new service.</p><p>At a later stage, we can remove the irrelevant tables from the newly promoted database and same we can do to the old master database remove tables which we have migrated to the newly promoted database.</p><p>This is a simple two-step process, where first we restrict services on a set of tables after defining table ownership by using database privileges model and at a later stage, we just create a slave database for data migration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf7094d8457" width="1" height="1" alt=""><hr><p><a href="https://medium.com/careem-tech/from-monolithic-to-microservices-database-bdf7094d8457">How to Break the Monolithic Database</a> was originally published in <a href="https://medium.com/careem-tech">Tech @ Careem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Database Changes at Scale]]></title>
            <link>https://medium.com/careem-tech/database-changes-at-scale-79f00b8354f?source=rss-c76a8300e11c------2</link>
            <guid isPermaLink="false">https://medium.com/p/79f00b8354f</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[database-administration]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[database-development]]></category>
            <category><![CDATA[aws-rds]]></category>
            <dc:creator><![CDATA[Khurram Naseem]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 10:08:14 GMT</pubDate>
            <atom:updated>2019-04-18T10:08:14.329Z</atom:updated>
            <content:encoded><![CDATA[<h3>Making database changes at scale</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzZPttutFENfCdpjQgvE8g.jpeg" /></figure><p>High Availability is key to any production environment. Anyone who has worked in consumer-based applications knows how hard it is to maintain uptime and make the application available 24/7 — especially in a fast-evolving environment, or one that needs to change quickly to meet demand for tough competition.</p><p>New features in applications mostly require changes at schema level of the database, and to make such changes with billions of rows in a single table is very hard. It always requires metadata lock on a table where you want to make changes and MySQL makes a copy of the table, which takes significant time depending on the size of the table. This become more complex if we also maintain referential integrity at the database level.</p><p>We’ve made database level changes of all sizes, and with few of proprietary databases for Oracle and SQL Server. To make changes on these databases, if they are running in an enterprise kind of environment, its not that hard you can handle downtime for few hours on low-peak hours, or even on weekends, to alter the schema or perform version upgrades.</p><p>Many of the big, globally successful startups choose MySQL as their back-end database, and we are no exception. Back in 2014, Careem databases were less than a few hundred gigabytes, but as Careem became a phenomenal success, the data growth skyrocketed and altering of the schema become extremely challenging.</p><p>At the start of 2016 we started looking at a few alternatives to make the changes in Careem database schema. I still remember our discussion with one Square engineer who made a utility for online schema change and it was available on GitHub with the name of Shift. But in our case, the biggest obstacle was database foreign key constraints which Shift didn’t support. We also has a look at Percona, the famous utility of pt-online-schema-change, but again, the problem was foreign key constraints, but we decided to go with the same trigger based approach.</p><p>Our experience with that approach went horribly wrong and at that time we decided never to go this route again. Careem runs its infrastructure on AWS and heavily use its RDS service for it all databases. We decided to start work on an alternative approach and since then we’ve been working to make any alterations first in the dedicated slave (read replica) and then use our terraform scripts to create the new master-slave hierarchy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*G6h9Mw8Wk76dBr8yXroxjg.png" /></figure><ol><li>Create a new Slave(read replica).</li><li>Stop replication manually.</li><li>Alter the schema - e.g. add columns/index</li><li>Resume replication.</li><li>Create new chain replication.</li><li>Shift all read-only traffic dedicated replicas.</li></ol><p>At the time of planned downtime:-</p><ol><li>Stop writing to master database by stopping applications.</li><li>Update Route53 to point to the new database.</li><li>Reboot the old database to release all connections.</li><li>Promote the new database as a new master.</li><li>Start all applications and verify they are making connections to new DB.</li><li>Make the new master as Multi-AZ.</li></ol><p>After creating the hierarchy we usually start redirecting traffic by using AWS Route53 weightage routing and at time of the swap, we take clean planned downtime of no more than 10 minutes to promote the new master.</p><p>The downside of this approach is, of course, a 10 min downtime, but we’ve learned that if you manage this at very low peak hours it’s manageable.</p><p>After the release of the new MySQL version 8.0.13 — which comes with the Tencent patch supporting instant alteration of the schema — it will make life easier but we are still evaluating this new MySQL feature.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79f00b8354f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/careem-tech/database-changes-at-scale-79f00b8354f">Database Changes at Scale</a> was originally published in <a href="https://medium.com/careem-tech">Tech @ Careem</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>