<?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 Rafael Gaino on Medium]]></title>
        <description><![CDATA[Stories by Rafael Gaino on Medium]]></description>
        <link>https://medium.com/@rgaino?source=rss-24a4408083df------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FQW4SB8--iIS9zTsAxJgLg.jpeg</url>
            <title>Stories by Rafael Gaino on Medium</title>
            <link>https://medium.com/@rgaino?source=rss-24a4408083df------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 14:23:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rgaino/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[A Day in the Life of a Tech Lead at Motorway]]></title>
            <link>https://medium.com/building-motorway/a-day-in-the-life-of-a-tech-lead-at-motorway-43b9ba09c316?source=rss-24a4408083df------2</link>
            <guid isPermaLink="false">https://medium.com/p/43b9ba09c316</guid>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[leadership]]></category>
            <dc:creator><![CDATA[Rafael Gaino]]></dc:creator>
            <pubDate>Thu, 12 May 2022 10:40:50 GMT</pubDate>
            <atom:updated>2022-05-12T10:40:50.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8j7f-D6KWEpUAS7ilMdUeg.png" /></figure><h4>Morning</h4><p>Before I am a Tech Lead at Motorway, I am a father of two wonderful girls, so my day actually begins by waking them up at 7am, making breakfast, getting them ready, and taking them to school. Recently my 9 year old learned how to make tapioca wraps and she&#39;s actually been taking care of breakfast. That&#39;s delegation, everyone! And even though it&#39;s ten times harder to clean her mess than actually making the breakfast, eventually she&#39;ll be ready to assume that task completely.</p><p>I get to work around 9:30am, which is home or our London office if I&#39;m feeling like a change of scenery, and the first thing is always coffee. As the caffeine starts to flow, I will catch up on Slack and see if there&#39;s any urgent issues or conversations happening that are waiting, or could benefit from my input. I&#39;ll take a look at my schedule for the day and get ready for standup at 10am.</p><p>As a Tech Lead during standup, I&#39;m not only concerned in reporting about my own work, but I am also watching everyone else&#39;s tickets, trying to identify potential blockers or issues. Sometimes seemingly simple tickets can be tricky or cause butterfly effects that are not so easy to spot, especially on a microservices architecture, so it&#39;s important to have knowledge about and consider the whole platform all the time.</p><p>At 10:15am standup has ended and the real day begins. I have a personal rule of not doing any work before I review every single PR assigned to me for code review. This is extremely important as their work is blocked until my review is done. It doesn&#39;t matter how long that takes, I will review every single one until I am done.</p><p>Once there are no more PRs to review, I allow myself to work on my own tickets. Unless of course, there are meetings… and there are always meetings!</p><p>Interviews, technical scoping, briefing sessions, one-to-ones, planning… it&#39;s all part of the job. Engineers love to say how much they hate meetings but at Motorway we try to make sure every meeting is necessary, the agenda is defined on the invite, and that everyone knows why they&#39;re there.</p><h4>Afternoon</h4><p>To make sure I get a few uninterrupted hours of focused work every day, I have my calendar blocked at certain times. This avoids context switching and allows me to focus completely on my tickets. Most days this time is in the afternoon, so after lunch I sit down, put on some music, and get to code.</p><p>At Motorway I work in the squad responsible for some of our most important internal tools. We take care of our internal Dashboard that our many agents in Brighton and Durban use all day every day to manage our user’s vehicle information, making sure they are ready to go on sale. We also build and maintain microservices that integrate with external systems, for customer service, accounting, CRM and others.</p><p>Twice a week I take an afternoon break at 3pm to pick up my daughters at school. I don&#39;t sneak out, this is a recurring event on my calendar and my squad is well aware of it. It&#39;s amazing to be able to work at a company that allows me to do that!</p><p>Once I&#39;m back and the girls are fed, I&#39;ll continue to work on my tickets or help other devs with their work. But before I call it a day, I&#39;ll do my best to review any PRs that were assigned to me during the day. As I said at the beginning, it&#39;s very important to unblock people and allow them to take their work to the finish line as fast and safely as possible.</p><h4>Evening</h4><p>As the work is done, I now get to focus on my family and myself. Some evenings I&#39;ll take my girls to piano lessons, or help them with homework. If I am at the office, then there&#39;s a high probability of going to the pub for a pint or two. And from there, I&#39;ll go home and play some games or watch some shows to relax. Currently I&#39;m playing Elden Ring and probably will be for months to come (I’m a huge Souls fan), and watching Severance (weird and brilliant, I am loving it).</p><p>All in all, being a Tech Lead has been the most exciting position I&#39;ve been in my career. There&#39;s a healthy mix of writing code, mentoring, architecting, planning and scoping. Every night I&#39;ll go to bed with a good sense of accomplishment while also looking forward to what&#39;s to come.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43b9ba09c316" width="1" height="1" alt=""><hr><p><a href="https://medium.com/building-motorway/a-day-in-the-life-of-a-tech-lead-at-motorway-43b9ba09c316">A Day in the Life of a Tech Lead at Motorway</a> was originally published in <a href="https://medium.com/building-motorway">Building Motorway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Running scheduled jobs on AWS Elastic Beanstalk]]></title>
            <link>https://medium.com/building-motorway/running-scheduled-jobs-on-aws-elastic-beanstalk-8c43bac6c556?source=rss-24a4408083df------2</link>
            <guid isPermaLink="false">https://medium.com/p/8c43bac6c556</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[scheduled-jobs]]></category>
            <category><![CDATA[elastic-beanstalk]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Rafael Gaino]]></dc:creator>
            <pubDate>Thu, 30 Sep 2021 15:30:29 GMT</pubDate>
            <atom:updated>2021-09-30T21:55:42.469Z</atom:updated>
            <content:encoded><![CDATA[<p>Motorway started on Heroku, as many start-ups do. It enabled us to move really fast in the beginning with a small team. Heroku abstracts away much of the complexity of a more bare bones hosting solution such as AWS, but these abstractions come at a price. It&#39;s a trade-off between simplicity and control over details of your platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dQWYfinE8FzLp0glHZb7hw.jpeg" /></figure><p>Since 2020 we have been migrating our microservices out of Heroku to Elastic Beanstalk, which provides a similar paradigm of running our apps and required little to no changes to our code base.</p><p>But many of the features we took for granted on Heroku were not so trivial to implement with Elastic Beanstalk. One of them was running scheduled jobs.</p><p>Some of our scheduled jobs have some tricky requirements to implement. The most important requirements were:</p><p><strong>. Exactly-once guarantee:</strong> our jobs must execute once and only once. This sounds trivial but in reality it&#39;s not.</p><p><strong>. Precision:</strong> our jobs need to be triggered bang on time, and we can&#39;t wait for a new instance to be initialised. For some specific jobs, we were looking for a precision of less than 1s.</p><p><strong>. Time zone support:</strong> our jobs need to run in a specific time zone, not UTC.</p><p>Those requirements prevented us from using solutions like CloudWatch Scheduled Events as it doesn&#39;t have time zone support. On top of that, AWS itself admits that <a href="https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/CWE_Troubleshooting.html#RuleTriggeredMoreThanOnce">events can be triggered more than once</a>. That level of precision was not good enough for us.</p><h3>The solutions that didn&#39;t work</h3><p>Search for <em>&quot;scheduled jobs on Elastic Beanstalk&quot;</em> and the results are underwhelming. Even <a href="https://aws.amazon.com/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/">AWS&#39;s official doc</a> on the topic has problems. It recommends creating a cron file on your environment, but that means that your job will trigger at the same time on all instances, which doesn&#39;t work on a scalable environment. You don&#39;t want several instances of your job being spawned simultaneously.</p><p>There are of course ways to ensure only one instance of your job is executed. This <a href="https://stackoverflow.com/questions/14077095/aws-elastic-beanstalk-running-a-cronjob">Stack Overflow discussion </a>for example recommends identifying a leader instance using the <em>leader_only</em> flag in the deploy config file and only creating the cron file in it, but that&#39;s absolutely the wrong way to do this because the leader only exists during the deploy phase. Afterwards, there is no such thing as a leader instance and if a scale-in event happens, your leader instance might be terminated and suddenly your scheduled job will not be executed anymore until a new deploy happens.</p><p>So you could let all instances trigger the scheduled job and pick a leader, using a lock mechanism (with Redis for example) or an internal Elastic Beanstalk script. But there&#39;s another problem with using cron files that defeats this approach: in the case of a scale-in or deploy event, your instance might be removed from the Autoscaling Group and then terminated, but your cron tasks will keep being triggered up until the moment of termination, which means your job might be killed while it&#39;s running.</p><h3>The solution that works</h3><p>Given all these issues, we opted for an approach consisting of 2 main pieces: a scheduled job triggerer microservice, and a library to ensure the jobs can finish in peace without fear of a sudden termination.</p><h4>The scheduler microservice</h4><p>The main reason for a new microservice responsible only for triggering scheduled jobs via http calls is to make sure the instance chosen to run the job is not marked for termination due to a scale-in or deploy event. When one of these events happen, Elastic Beanstalk will first remove the instance from the Autoscaling Group and drain all connections from it. This means that when the scheduler requests an application to run a job, we can be sure the instance is not being scheduled for termination.</p><p>It also gives us an easy and centralised way of configuring our jobs. We used the <a href="https://www.npmjs.com/package/node-schedule">node-schedule</a> package which has a cron-like syntax and timezone support out of the box. Having our own microservice also gives us the option of easily building an interface for it that makes it easy to adjust, pause or force-trigger jobs without any code changes or having to ssh into an instance for a manual trigger.</p><p>Our scheduler microservice also suffers from scale and deploy events and because of rolling deploys, it&#39;s possible that it will have more than 1 instance active at any moment. So we used a lock mechanism with Redis to ensure that even if multiple instances have a schedule triggered, only one will acquire the lock and actually make the request.</p><p>We then added a new endpoint on all our microservices using our internal API framework library that receives the request, spawns a new process to execute the script (we use Node.js and we don&#39;t want to interfere with the main thread) and logs the outcome.</p><h4>Termination protection</h4><p>But even if we request the job before an instance is marked for termination, we can&#39;t guarantee it won&#39;t be marked for termination immediately after our request is accepted, and if the job doesn&#39;t finish quickly, the instance termination might happen before the job completes.</p><p>To eliminate this possibility, we took advantage of <a href="https://docs.aws.amazon.com/autoscaling/ec2/userguide/lifecycle-hooks.html">EC2 Lifecycle Hooks</a>. Whenever an instance is scheduled for termination, it&#39;s first removed from the Autoscaling Group and then, if lifecycle hooks are enabled, EC2 will send a notification requesting permission to terminate the instance.</p><p>When our applications start a task, they first acquire an instance termination lock. So if an instance has an active lock and our system gets notified about EC2 wanting to terminate it, it will simply not allow the termination until the task is done. Once the task finishes, we know it won&#39;t receive any new requests because it&#39;s already removed from the Autoscaling Group, so we&#39;re clear to allow the termination.</p><h4>In conclusion</h4><p>As I said in the beginning, it&#39;s a trade-off between simplicity and control. This is in no way the only possible solution, but it checks all the boxes in our requirements list and gives us the option of expanding it in the future.</p><p>Our scheduler microservice can be extended to not only trigger jobs in other applications but trigger automatic communications or any other task that must happen in a scheduled manner.</p><p>Our instance termination protection can now be used to protect any task, like one-off scripts that might take a longer time to complete.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8c43bac6c556" width="1" height="1" alt=""><hr><p><a href="https://medium.com/building-motorway/running-scheduled-jobs-on-aws-elastic-beanstalk-8c43bac6c556">Running scheduled jobs on AWS Elastic Beanstalk</a> was originally published in <a href="https://medium.com/building-motorway">Building Motorway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What I learned from deleting a production database]]></title>
            <link>https://medium.com/building-motorway/what-i-learned-from-deleting-a-production-database-ef5756bbaad1?source=rss-24a4408083df------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef5756bbaad1</guid>
            <category><![CDATA[production]]></category>
            <category><![CDATA[no-blame-culture]]></category>
            <category><![CDATA[disaster-recovery]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Rafael Gaino]]></dc:creator>
            <pubDate>Tue, 17 Aug 2021 15:17:03 GMT</pubDate>
            <atom:updated>2021-08-17T15:17:03.200Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WEJ2Wde8XGkfutLs" /><figcaption>Photo by <a href="https://unsplash.com/@elisa_ventur?utm_source=medium&amp;utm_medium=referral">Elisa Ventur</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The funny thing about the day I dropped our main production database is that I can&#39;t really remember what I was working on. Instead, what I remember is how I felt the second my finger hit the Return key on that script, and how that day turned into a lesson of disaster recovery and a brilliant display of a no blame culture at <a href="https://motorway.co.uk/">Motorway</a>.</p><h3>Part I: The Drop</h3><p>In the early days of Motorway we were just 3 engineers wearing all the hats we could find. It wasn&#39;t uncommon for us to have to login to a database with write credentials to manually change some data. And that’s the first lesson here people: anything that can go wrong, will go wrong. Murphy’s Law spares no one.</p><p>As I was working on that thing I don&#39;t remember what, I had a script that heavily modified some tables. To make development quicker, I wrote a script that would drop my local DB and re-create it from a dump file. And that was when I was called to investigate some urgent production problem. So I logged in to the production DB with full permissions, and did what I had to do. I closed my laptop for about an hour, had a break and came back later to continue the work I was doing before.</p><p>That was when I ran the script using the production connection.</p><p>I instantly knew what I had done. My hands begun to shake, and my stomach begun to churn. I took a deep breath and decided two things right then: I was going to own that mistake, and I was going to see the fix through.</p><h3>Part 2: Owning My Mistake</h3><p>I immediately turned to Slack to notify everyone, but it was late already and most people were already offline. So I opened our emergency WhatsApp channel and wrote a short and clear message: I had dropped one of the production DBs by accident and was looking for ways to restore it. If anyone could join and work with me, please do as soon as possible.</p><p>Before people could properly react I found a backup on an external service, but it was a few hours old. I knew most of the data missing from this period could be pieced together, by other DBs, by our logs and by external storages, so I decided to act to restore the service as quick as possible and begin the process of repopulating the gap. I restored the DB and the service was operational again. The total outage was only 18 minutes long. My hands stopped shaking, but we were not out of the woods yet. That&#39;s when my colleagues came online and started to help me piece the puzzle together.</p><h3>Part 3: Restoring and Learning</h3><p>As we worked together to fill the data gap, I was amazed by how I felt that I was the only one who was incredibly mad at me. Everyone was focused on the solution. We wrote scripts to collect data from other sources and we were actually able to fill the data gap almost completely. I worked overnight to complete these scripts, and before the rest of the company woke up, things looked normal.</p><p>We communicated the incident to the rest of the company and explained what kind of anomalies they could expect for the affected records. I wrote a detailed email to my manager and the CEO where I explained how something like this could even happen, how it was restored, and how to prevent this from ever happening again (which it didn&#39;t).</p><p>The responses from the founders were very gratifying. Here I&#39;ll paste some of the things they wrote: <em>&quot;this isn’t your fault and could just have easily happened to anyone else on the team (…) This is a wake up call to all of us over database security and access (…) This incident is bad, but it could also have been an awful lot worse. Let’s take it as an opportunity to dramatically improve our processes around data durability.&quot;</em>, and also <em>&quot;It’s how we handle and learn from things like this that matters, so well done — and thank you </em>😊<em>&quot;</em></p><p>You read that right. They wrote <em>&quot;thank you&quot; </em>with a smile emoji on an email where I said I had dropped a production DB. If this is not a great place to work, I don&#39;t know what is.</p><h3>Part 4: The Aftermath</h3><p>Once the dust settled, we went through a review of security and access, wrote a guide around Disaster Recovery, ensured credentials had limited power, and communication of problems were done properly. This happened over 2 years ago, and we haven&#39;t had any disaster ever since. But if (or when) it comes, we’ll be ready for it.</p><p>We plan as much as we can, but things will sometimes go wrong. Mistakes are rarely made, and when they do we’ll learn, come together as a team, fix it, and never let them happen again.</p><p>This whole ordeal was a great lesson for me. At the time I was only a few months with the company, and I fully expected to be fired or at the very least reprimanded. But instead I saw my colleagues coming together to help me fix my mistake as if it had happened to them. I saw our leadership commend me in communicating and owning my mistake, and I saw a great display of a no blame culture. And when (or if) this happens to anyone else here, I&#39;ll be sure to react the same way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef5756bbaad1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/building-motorway/what-i-learned-from-deleting-a-production-database-ef5756bbaad1">What I learned from deleting a production database</a> was originally published in <a href="https://medium.com/building-motorway">Building Motorway</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>