<?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 Maria Ehsan on Medium]]></title>
        <description><![CDATA[Stories by Maria Ehsan on Medium]]></description>
        <link>https://medium.com/@maria.ehsan63?source=rss-2942151c1283------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CHuxCqDtWGun1RugK5L1Xw.jpeg</url>
            <title>Stories by Maria Ehsan on Medium</title>
            <link>https://medium.com/@maria.ehsan63?source=rss-2942151c1283------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:49:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@maria.ehsan63/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[Careem — a Journey to Remember]]></title>
            <link>https://medium.com/@maria.ehsan63/careem-a-journey-to-remember-425f0fc3730?source=rss-2942151c1283------2</link>
            <guid isPermaLink="false">https://medium.com/p/425f0fc3730</guid>
            <category><![CDATA[careem]]></category>
            <category><![CDATA[journey]]></category>
            <dc:creator><![CDATA[Maria Ehsan]]></dc:creator>
            <pubDate>Fri, 04 Nov 2022 08:42:23 GMT</pubDate>
            <atom:updated>2022-11-04T22:59:14.340Z</atom:updated>
            <content:encoded><![CDATA[<h3>Careem — a Journey to Remember</h3><blockquote>On August 2022 I decided to execute DELETE FROM user WHERE name = “maria.ehsan” on my Careem server that has been running for a little over 5 years.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gWUVHnXCmKqoMmo5xIBmpg.png" /></figure><p>I joined Careem on 12th June 2017 as a Database Engineer immediately after I finished my university’s final year examinations. I received the offer in April, 2 months before my final exams as a result of a recruitment drive Careem conducted at my university. This was a proud moment for my family, not because I am about to join Careem but because I already landed the job before graduation.</p><p>You must be wondering why I opted to become a Database Engineer. Let me start by telling you a true story, a story I’ve never shared with anyone. I still remember it was my final project of a Database course in 6th semester, and my professor asked me what database engine have you used. Fairly simple question that anyone could answer. And I said its JDBC! He looked at me for good 60 seconds, and wrote F in front of my name in his laptop. So honestly it was not me who decided to become a Database Engineer, it was my HR who played well and convinced me.</p><p>Now I joined Careem as a Database Engineer who knows nothing about Databases, there was no other person in my team, just me and my manager. This presented a huge challenge as well as enormous responsibility, because when you are working in a team you grow at twice the rate. I knew it will be difficult for me more than for anybody else. This actually encouraged me to take up the gauntlet and I spent days and nights on just learning about databases and how different databases work. After few months of my joining I started managing Careem’s production databases which made me more anxious, but this was the opportunity for me to grow.</p><p>What’s wonderful about it all is that Careem never fails to appreciate your efforts and always recognizes your work. I still remember I went to Careem’s Dubai office (which we call Basecamp) in 2018 for some database meeting, my first year in Careem wasn’t completely finished. I was meeting my colleagues in Dubai for the first time and they were like “Oh! So you’re the famous Maria, the rockstar!”. Events like these always encourage you to do more.</p><p>Another reason why Careem is a journey to remember is because I met a coworker who is now my life partner. No, we never declined any meeting that included both of us if we fought at home. He was a developer (now moved to an engineering manager role because obviously I proved lucky for him), so now we both become a full stack engineer.</p><p>Here you must be wondering that why did I leave this heaven of a job where I was having this amazing journey. Well I would say it was the fear of being in my comfort zone and the urge to explore new things in life.</p><p>I am certain that the experience I have got during these 5 years (which is a very small number) wouldn’t have been possible if it wasn’t Careem. Not only have I learnt about databases and my job, but I also grew up in Careem. Careem has seen my journey on how I turned into a married women and now a mother of 9 months old daughter.</p><p>Now a girl who didn’t know anything about databases 5 years back becomes a women who loves every bit of her job. Today I am working in Amazon as a Database Specialist Solutions Architect and moved to UAE with my husband and my daughter. Working in a FAANG company in such early years of your career is not a small thing and I believe that Careem made it possible for me by providing me with the opportunities to learn and grow in my career.</p><p><em>Thanks to Careem — a journey to remember!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=425f0fc3730" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Create Multi Tier RDS Hierarchy using Terraform]]></title>
            <link>https://medium.com/@maria.ehsan63/create-multi-tier-rds-hierarchy-using-terraform-73fc899baaac?source=rss-2942151c1283------2</link>
            <guid isPermaLink="false">https://medium.com/p/73fc899baaac</guid>
            <category><![CDATA[optimization]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[rds]]></category>
            <category><![CDATA[infrastruture-as-code]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Maria Ehsan]]></dc:creator>
            <pubDate>Sat, 02 Jul 2022 17:51:16 GMT</pubDate>
            <atom:updated>2022-07-02T17:51:16.861Z</atom:updated>
            <content:encoded><![CDATA[<p>We all have been using Terraform as IAC (Infrastructure As Code) to provision infrastructure resources on Cloud. Terraform is super easy when it comes to provision single resources for example a security group, a vpc and an RDS. But what if you have to create more complex array of resources?</p><p>What if you have an RDS hierarchy that looks like the one below?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6htXn3__7QvSbqomQtWgyg.jpeg" /><figcaption>Multi Tier RDS Hierarchy</figcaption></figure><blockquote><strong>You Ask:</strong> Why would anyone have such ugly database hierarchy?<br><strong>My Answer:</strong> <a href="https://aws.amazon.com/rds/features/read-replicas/#:~:text=AWS%20Management%20Console.-,Amazon%20RDS%20for%20MySQL%2C%20MariaDB%2C%20PostgreSQL%2C%20Oracle%2C%20and,replicas%20to%20each%20DB%20Instance.">Due to AWS restriction on the number of read replicas from one RDS instance.</a> Since you can not have more than 5 read replicas from one RDS instance, you can create multi tier hierarchy as the one above.</blockquote><p><em>My example in this article is focused on RDS hierarchy but this information should apply on any other resource creation.</em></p><p>So when I started creating this hierarchy using terraform, there were few things that I wanted to achieve:</p><ol><li>I wanted to create this whole hierarchy in one go, using single cd pipeline</li><li>I did not want to define similar resources multiple times</li><li>I wanted to run some commands on resources in each tier before moving to the next tier.</li></ol><p>So in order to create multiple resources that are similar (like above), you often end up in producing lots of duplication in code.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4ulrnclIVdmja-IYI2G6Vw.png" /><figcaption>Duplication of code for multiple similar resources</figcaption></figure><p>Imagine if you have 10 more RDS instances that you want to create. This results in unnecessary code duplication and would create shotgun surgery (it’s a code smell 😉)</p><p>Terraform makes life much easier as it provides the ability to create <strong>List. </strong>Well yes, you can use the same list to define variables for multiple resources in a module. You can create a List of RDS instances, define configurations that are different for each resource in separate blocks, and group all the configurations (that should be same for multiple resources) only at once.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iRQUT0CunPiZ-Nck_Rnvfw.png" /><figcaption>Group similar configurations for multiple resources</figcaption></figure><p>And while defining the resource you can lookup on variables (that can be different for these similar resources) using index. <br>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pNILg_HRjQpNCnAQhfDNsQ.png" /><figcaption>Lookup and Count to get values of multiple resources</figcaption></figure><p>Great, so you now know how to efficiently define similar resources that has few different configurations.</p><p>Now what if you want to run some commands after creation of each resource? So in RDS whenever we create a read replica with different parameter group we need to reboot the instance to apply the parameter settings. In our Multi Tier RDS hierarchy we have attached different parameter group on each read replica, hence these read replicas needs to be rebooted after creation. Terraform does not depict this scenario and reboot the instance, so we have to run explicit commands to reboot each instance. Luckily terraform provides provisioners.</p><p>For example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*68_JZXk9pmNFOAW0QdXxdA.png" /><figcaption>Provisioner that runs after creation of resources</figcaption></figure><p>That’s all folks 🙂 In this article we tried to look at few tips and tricks that we can use to optimize our terraform code.</p><p>You can find the full source code to create multi tier RDS hierarchy <a href="https://github.com/maria-ehsan/rds-hierarchy">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73fc899baaac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Right Sizing for AWS RDS Instances]]></title>
            <link>https://medium.com/@maria.ehsan63/right-sizing-for-aws-rds-instances-acb3c3e3a3c5?source=rss-2942151c1283------2</link>
            <guid isPermaLink="false">https://medium.com/p/acb3c3e3a3c5</guid>
            <category><![CDATA[rightsizing]]></category>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[rds]]></category>
            <dc:creator><![CDATA[Maria Ehsan]]></dc:creator>
            <pubDate>Mon, 20 Jun 2022 10:52:02 GMT</pubDate>
            <atom:updated>2022-06-20T13:16:16.630Z</atom:updated>
            <content:encoded><![CDATA[<p><em>We can save huge infrastructure cost by provisioning RDS Instances based on the workload generated by the Applications.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YE7SB-bmrcmI1EHn6R161A.jpeg" /></figure><p>If you are working on Cloud Databases, you often realize that you are spending hefty amount of money for managed services for example, RDS. This realization would make you hustle to find for solutions that results in lower cost. We came across this realization long ago, so we decided to build an automated solution to reduce the cost of our RDS instances.</p><p>Often there are three strategies to reduce the cost of RDS instances. i.e<br>1. Right Sizing<br>2. Use of Reserved Instances<br>3. Termination of Idle Instances</p><p>In this article I’ll walk you through how we build our own Recommendation System to Right Size AWS RDS Instances. So the major cost of AWS RDS comes from <strong>instance class</strong>, <strong>storage</strong>, and <strong>provisioned iops</strong>. <em>vcpus</em> and <em>memory</em> is determined by the instance class whereas storage determines <em>disk</em> and <em>iops</em>.</p><blockquote>Goal for Right Sizing should be to adjust the database instance size to match the workload generated by the application, without compromising on performance.</blockquote><p>For our recommendation system we decided to use the last 60 days of data, and make decisions based on 99th Percentile metrics. We have considered following metrics:</p><ul><li>CPU Utilization</li><li>Memory Utilization</li><li>Disk Utilization</li><li>Provisioned IOPS Utilization</li><li>Database Connections</li></ul><p>Based on the above metrics we categorized each instance as <em>Under Provisioned</em>, <em>Optimized</em>, and <em>Over Provisioned</em>. We also use last 14 days database connections as metrics to determine if the instance is idle and should be terminated. Instances with insufficient workload information will not have any recommendation. Below is the step by step process that shows how recommendations are generated considering Idle Connections, Latest Generation Classes, Instance Class, Storage and Provisioned IOPs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iJ2VepARMjsik8NM-6UTuQ.jpeg" /><figcaption>Flow Chart for Right Sizing Recommendation System</figcaption></figure><blockquote>The thresholds defined in the above flowchart are the ones that worked best for us, you can define it as per your database criticality and workload.</blockquote><p>One part of our recommendation is to move to Latest Generation Classes for example if we are using r3, this should be moved to r5 (latest generation as of writing this article) as Latest Generation classes has improved performance with lower cost.</p><p>Our plan for Right Sizing was to make one-incremental change with multiple iterations. For example if the instance is using 4xlarge, is <em>Over Provisioned</em> and needs to be downgraded we will downgrade it to 2xlarge first and measure the performance instead of downgrading it directly to xlarge or large. Similarly if the allocated storage needs to be increased to match the workload we will increase it to 5GB or 10% of the Allocated Storage (whichever is higher), as once you increase the storage on AWS RDS you can not decrease it. Thus it is good to take small incremental steps to make sure that all our instances matches the workload. These iterations should go on until all instances reside under Optimized Category.</p><p><em>Thank you for reading! :)</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acb3c3e3a3c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Increment Primary Keys Reaching its Limit]]></title>
            <link>https://medium.com/@maria.ehsan63/auto-increment-primary-keys-reaching-its-limit-aeef0b3ae28f?source=rss-2942151c1283------2</link>
            <guid isPermaLink="false">https://medium.com/p/aeef0b3ae28f</guid>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[auto-increment]]></category>
            <dc:creator><![CDATA[Maria Ehsan]]></dc:creator>
            <pubDate>Fri, 10 Jun 2022 22:26:34 GMT</pubDate>
            <atom:updated>2022-06-18T11:12:30.437Z</atom:updated>
            <content:encoded><![CDATA[<p>I work on large scale databases that runs millions of transactions every second, consists of very large multi-terabyte, multi-million rows of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*X3mnVKLjYZJOL_nu.jpg" /></figure><p>In Relational databases, we often make auto-increment primary keys, so was the case with one of our critical production databases. On one fine day, our applications started facing error stating that:</p><blockquote>java.sql.SQLIntegrityConstraintViolationException: Duplicate entry ‘2147483647’ for key ‘PRIMARY’</blockquote><p>Upon debugging we figured out that our largest table’s primary key column has reached its maximum limit. In order to fix it, we immediately needed to alter the data type of this column and change it from INT to BIGINT. This column alteration took 28 hours on table of size around 200 GB. During this time the table became completely unresponsive as ALTER statement acquires exclusive lock on table that block reads and writes until ALTER finishes. Luckily small part of our business was dependent on this table, and the table’s id wasn’t used as foreign key in any other table, else we first needed to alter all these child tables which would have taken much more time.</p><blockquote>With Auto increments, when a column reaches the upper limit of the data type, the next attempt to generate a sequence number fails. This means that until you update the data type to accommodate bigger values, you won’t be able to insert new records in the table.</blockquote><h4><strong>Below are the steps to ALTER Primary Key data type of any table in MySQL:</strong></h4><p>Assume that the primary key column is named as <em>id </em>in table<em> </em><em>t1</em>. And we want to change datatype from INT to BIGINT.</p><ul><li><em>Identify all Foreign Key constraints that refers to the </em><em>id column of table </em><em>t1</em></li><li><em>Drop all Foreign Key constraints identified in above step</em></li><li><em>Drop the Primary Key constraint on </em><em>id</em></li><li><em>Run Alter table to change primary key data type from INT to BIGINT</em></li><li><em>Run Alter table to change foreign keys data type from INT to BIGINT</em></li><li><em>Add back Primary Key constraint to </em><em>id</em></li><li><em>Add back Foreign Key constraints that referenced </em><em>id</em></li></ul><blockquote>We can not directly update primary key data type if it is referenced in any other table hence above steps are necessary.</blockquote><p>For large tables, changing the data type of any column requires more than 24 hours depending on the size of the table. Therefore it is necessary to check in advance if columns are reaching their maximum limit of the data type. It is also very important to have predictive algorithms in place that can predict when the data type can reach its limit and produce alerts.</p><p>Below is the query to check how much limit tables have used on <em>auto_increment</em> columns.</p><pre>SELECT table_name, column_name, column_type,<br>(  CASE data_type<br>   WHEN &#39;tinyint&#39; THEN 255<br>   WHEN &#39;smallint&#39; THEN 65535<br>   WHEN &#39;mediumint&#39; THEN 16777215<br>   WHEN &#39;int&#39; THEN 4294967295<br>   WHEN &#39;bigint&#39; THEN 18446744073709551615<br>   END &gt;&gt; IF(LOCATE(&#39;unsigned&#39;, column_type) &gt; 0, 0, 1)<br>) AS column_limit, AUTO_INCREMENT as max_value, ROUND(AUTO_INCREMENT / (<br>   CASE data_type<br>   WHEN &#39;tinyint&#39; THEN 255<br>   WHEN &#39;smallint&#39; THEN 65535<br>   WHEN &#39;mediumint&#39; THEN 16777215<br>   WHEN &#39;int&#39; THEN 4294967295<br>   WHEN &#39;bigint&#39; THEN 18446744073709551615<br>   END &gt;&gt; IF(LOCATE(&#39;unsigned&#39;, column_type) &gt; 0, 0, 1)<br>  ) * 100, 1) AS auto_increment_ratio_in_percent<br>FROM<br>information_schema.columns<br>INNER JOIN information_schema.tables <br>USING (table_schema, table_name)<br>WHERE table_schema = &#39;<em>your_schema</em>&#39;<br>AND extra=&#39;auto_increment&#39; <br>ORDER BY auto_increment_ratio_in_percent DESC, max_value DESC;</pre><p><em>Thank you for reading!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aeef0b3ae28f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>