<?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 Felipe Álvarez on Medium]]></title>
        <description><![CDATA[Stories by Felipe Álvarez on Medium]]></description>
        <link>https://medium.com/@falvarezm97?source=rss-fc4f2a8feca1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*YLS9idIzrAGi5smDe-fOSg.png</url>
            <title>Stories by Felipe Álvarez on Medium</title>
            <link>https://medium.com/@falvarezm97?source=rss-fc4f2a8feca1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 20:01:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@falvarezm97/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[Comments? NO GOD PLS NO! ]]></title>
            <link>https://medium.com/mercadona-tech/comments-no-god-pls-no-873c7153f9f8?source=rss-fc4f2a8feca1------2</link>
            <guid isPermaLink="false">https://medium.com/p/873c7153f9f8</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[good-practices]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Felipe Álvarez]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 11:40:10 GMT</pubDate>
            <atom:updated>2024-07-17T11:45:43.939Z</atom:updated>
            <content:encoded><![CDATA[<h3>Comments? NO GOD PLS NO! 🥴</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1TYmBwxMfSwKciKd.png" /></figure><p>👋 Hi everyone! I’m Felipe Álvarez, Backend Engineer at <a href="https://medium.com/u/7aeeefb24843">Mercadona Tech</a>. Today, I want to talk about one of the basics of Clean Code: <strong>don’t comment.</strong></p><p>This is one of the most common misconceptions in Software Development.</p><p>Perhaps you entered here because you use comments every day and think I’m crazy. I can’t complain about you because I was in the same situation a few years ago. I used to comment on all my code (or at least the tricky parts) because I wanted everyone to understand it.</p><p>And here is the key: what type of code are you writing that needs some explanation with comments? As <a href="https://medium.com/u/ffa32c7b39eb">Robert Martin</a> says in the awesome book “Clean Code”:</p><blockquote>The proper use of comments is to compensate for our failure to express ourself in code</blockquote><p>And here is the problem: comments are like documentation: <strong>they lie</strong> and become outdated as time goes by because you may change the code, but you will probably forget to change the comment.</p><p>Also, we spend more time reading code than writing it, and it’s more challenging to read complex code with explanations in comments rather than reading simple, clean, and self-explanatory code.</p><p>So, what can we do? How about caring about the readability of our code? How about trying to keep our code as clean as possible so it explains itself? 🌚</p><p>I know that there are many types of comments, and I know that in some really specific situations the use of comments could be justificated (for instance, inside a Jenkins Pipeline or in some config file), but I’m going to talk about what I think are the 2 most used cases of comments during development:</p><ul><li>The comments for “WHAT?”</li><li>The comments for “WHY?”</li></ul><h4>The comments for WHAT?</h4><p>I’m sure you have seen a lot of times things like this:</p><pre>class SomeClass:<br>  def some_method(self, some_object):<br>    ...<br>    # If the state of the object is 1, it means that the previous process<br>    # have failed, so we have to modify its values<br>    if some_object.get_state() == 9:<br>      some_object.set_some_value(&quot;a_value&quot;)<br>      some_object.set_another_value(&quot;another_value&quot;)<br>    ...</pre><p>Maybe this is not the best example but I think you can get me. If you notice, the comment says that the status of failure is 1, but in the code is 9. What happend here? Maybe some time ago that status was 1, but then it changed, and someone forgot to change the comment as well. What can we do? Remove the comment? Change the comment? Change the code? I think you can understand me.</p><p>The best way for getting rid of this type or comments is <strong>using methods</strong>. Let’s see this:</p><pre>class SomeClass:<br>  def some_method(self, some_object):<br>    ...<br>    self._manage_state_after_some_process(some_object)<br>    ...<br><br>  def _manage_state_after_some_process(self, some_object):<br>    if not some_object.has_a_valid_state():<br>      some_object.reset_state()</pre><p>As you can see, removing the comment has greatly improved our code! Now, we use the rule of “Tell, don’t ask,” we have better naming, and the comment explanations are now embedded in our code. It’s easy to read and easy to maintain.</p><h4>The comments for WHY?</h4><p>The other type of comments usually are for explaining the reasons behind some block of code. Something like this:</p><pre>class SomeClass:<br>  def some_method(self, some_object):<br>    ...<br>    # We need to store all datetimes as UTC in ddbb because blablabla<br>    some_object.convert_some_date_to_UTC()<br>    ...</pre><p>For these cases, the best way to attack them is by <strong>creating specific tests</strong> for those cases. As I said before, a comment probably gets outdated as time goes by, or someone would remove it.</p><p>But if there is a part of your code that needs to be done for whatever reason, the best way to assuring that is simple: having a test for that! A test would not get outdated, and if you or someone else accidentally remove that important part of code, the test will warn you.</p><p>Also, you can give the same context with a good naming in the test you gave in the comment. Let’s see this:</p><pre>class SomeClass:<br>  def some_method(self, some_object):<br>    ...<br>    some_object.convert_some_date_to_UTC()<br>    ...</pre><pre>@pytest.mark.django_db<br>class TestSomeClass:<br>  def test_some_object_date_is_saved_as_UTC_when_doing_some_use_case(self):<br>    some_object = some_object_builder().build()<br><br>    SomeClass().some_method(some_object)<br><br>    assert some_database_object.objects[0].some_date.tzinfo == pytz.utc</pre><p>As you can see, now we have all the necessary context within the name of the test, and we also have a way to ensure this code never stops doing what it is supposed to be doing 😋</p><p>Last but not least, I know sometimes we need comments, or at least they are really useful, but I think that having a mindset of “no comments”, can be really useful and can help us a lot to improve our codebase, make better decisions and build a much robust, readable and maintainable code.</p><p>Thanks for reading; keep it clean 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=873c7153f9f8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadona-tech/comments-no-god-pls-no-873c7153f9f8">Comments? NO GOD PLS NO! 🤮</a> was originally published in <a href="https://medium.com/mercadona-tech">Mercadona Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Design Patterns Series ]]></title>
            <link>https://medium.com/mercadona-tech/quick-design-patterns-series-1414555abe71?source=rss-fc4f2a8feca1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1414555abe71</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Felipe Álvarez]]></dc:creator>
            <pubDate>Fri, 24 May 2024 15:08:37 GMT</pubDate>
            <atom:updated>2024-05-24T15:08:39.155Z</atom:updated>
            <content:encoded><![CDATA[<h3>Index</h3><ul><li><a href="https://medium.com/p/4ff3d49710b4/">Chapter One: The Strategy Pattern</a></li></ul><p>👋Hi everyone! My name is <a href="https://www.linkedin.com/in/felipe%C3%A1lvarez/">Felipe Álvarez</a>, and I am a proud member of the engineering team at Mercadona Tech. The other day, while talking with my backend colleagues, we thought it would be cool to make a series of posts about our beloved <strong>Software Design Patterns</strong> and how we apply them daily.</p><p>We are going to take as a reference our small knowledge, the amazing web <a href="https://refactoring.guru/">refactoring.guru</a>, and the “<a href="https://www.oreilly.com/library/view/head-first-design/0596007124/">Head First Design Patterns (Eric Freeman &amp; Elisabeth Robson)</a>” book, as we love it (I encourage you to read it 😉); and our idea is to summarize as much as we can the principal patterns that appear there. We might also include other ones too.</p><p>My intention with this post is to keep it as an index for the whole series. I will add the links to the articles as we write them.</p><p>The main goal here is to share with you a concise explanation and some simple examples about our favourite design patterns that we use daily, furthermore explaining why and how we use them.</p><p>Last but not least, this is not the ultimate source of truth and we probably don’t understand or use the patterns the way you do, so let us know about your use cases. Any feedback is more than welcome!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*AvPcSNLMPj9N24v4.jpg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1414555abe71" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadona-tech/quick-design-patterns-series-1414555abe71">Quick Design Patterns Series 🎨</a> was originally published in <a href="https://medium.com/mercadona-tech">Mercadona Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick Design Patterns Series 1: The Strategy Pattern ]]></title>
            <link>https://medium.com/mercadona-tech/quick-design-patterns-series-1-the-strategy-pattern-4ff3d49710b4?source=rss-fc4f2a8feca1------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ff3d49710b4</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Felipe Álvarez]]></dc:creator>
            <pubDate>Fri, 24 May 2024 11:28:41 GMT</pubDate>
            <atom:updated>2024-05-24T11:28:41.776Z</atom:updated>
            <content:encoded><![CDATA[<p>👋 Hi everyone! My name is <a href="https://www.linkedin.com/in/felipe%C3%A1lvarez/">Felipe Álvarez</a>, and I work as a Backend Engineer at Mercadona Tech. This is the first chapter of the Design Patterns series we want to write. You can see the rest of them <a href="https://medium.com/p/1414555abe71/">here</a>, in case you want 😉</p><p>So… let’s talk about the Strategy Pattern. <a href="https://refactoring.guru/design-patterns/strategy">Refactoring guru</a> defines it like this:</p><blockquote><strong>Strategy</strong> is a behavioral<em> </em>design pattern that lets you define a family of algorithms, put each of them into a separate class, and make their objects interchangeable.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*273LhAYA9Q0zeIcV.jpg" /></figure><p>One of the reasons I find this pattern so compelling is its ability to illustrate the benefits of adhering to SOLID principles, <strong>particularly the practice of programming to interfaces rather than implementations</strong>.</p><p>In the end, all good programming practices are based on decoupling your code and reducing dependencies, and I can’t think of a better way to do that than <strong>inverting your dependencies by injecting them</strong> (and using interfaces for the contracts between your components).</p><p>This is also the main idea behind Hexagonal Architecture’s magic, and interfaces are the best way to separate components between different layers.</p><p>And this is exactly what the Strategy Pattern does. Let me explain it with an example of one of our use cases.</p><p>Let’s say that in our physical stores, our users (<strong>gerentes)</strong> receive trucks full of containers with products daily. Once a container has arrived at the store, they tell us (by using our Stocks application) that the container has arrived, so then we can add the content of that container (the products) to the store’s stock. This action is called “reception” of a container.</p><p>To perform that action, we take the container information and call a Mercadona IT service to perform that reception.</p><p>A simplified flow would be like this:</p><p>Physical container arrives at the store → The gerente scans the label of that container with the V6 → We take that container info and call a Mercadona IT service → They add the products of that container to the store stock → We confirm to the gerente that the container has been receptioned correctly</p><p>Okay, until now, everything seems easy, but here comes the problem: not all containers are received the same way. Let’s say that we have 2 different types of containers: normal containers and fish containers, and for each type of container, we need to call a different Mercadona IT service.</p><p>How can we solve this? Let’s see some code examples:</p><p>We have the following endpoint for receptions of a container:</p><pre>POST /api/containers/some_uid/reception/</pre><p>And then the view (the infrastructure entry point) for that endpoint:</p><pre>class ReceptionContainerView(APIView):<br>  def post(self, request, uid: str):<br>    container = ContainerRepository().retrieve_by_uid(Uid(uid))<br><br>    ReceptionContainer().execute(container)<br>    <br>    return Response(status=200)</pre><p>(Some of you have probably seen that we have a repository for accessing the database and a value object for the uid. We don’t use them exactly like that, but it’s easy to explain this, but let’s keep that thing for another post 🤫)</p><p>And then the action:</p><pre>class ReceptionContainer:<br>  def execute(self, container: Container) -&gt; None:<br>    if container.is_fish():<br>      return MercadonaFishContainerService().call(container.internal_id)<br>    <br>    return MercadonaContainerService().call(container.internal_id)</pre><p>As you can see, with this approach, our action is totally coupled with the implementation of the services (infrastructure), and we have a really ugly situation inside. What will happen if some of the implementations change? Or if now we have one more service to another type of container?</p><p>So… So… now it’s time to think of a solution and give it a cool refactor.</p><p>How about taking those <strong>external dependencies</strong> out of the action? Okay, we can create a class that encapsulates everything we need to call the external service. We can define a contract (interface) for this:</p><pre>class ReceptionProvider(ABC):<br>  @abstractmethod<br>  def provide(container_id: str) -&gt; None:<br>    ...</pre><p>We have taken the convention of calling this type of class “provider,” but you can use any other name like “service” or whatever you want 😉</p><p>So now we have our pretty interface, let’s inject it into our action:</p><pre>class ReceptionContainer:<br>  def __init__(self, reception_provider: ReceptionProvider):<br>    this._reception_provider = reception_provider<br><br>  def execute(self, container_id: str) -&gt; None:<br>    self._reception_provider.provide(container_id)</pre><p>As you can see, our action is <strong>now totally decoupled</strong> with specific infra implementations. That’s nice!</p><p>What next? Let’s create the implementations for this interface:</p><pre>class MercadonaReceptionProvider(ReceptionProvider):<br>  def provide(container_id: str) -&gt; None:<br>    MercadonaContainerService().call(container_id)</pre><pre>class MercadonaFishReceptionProvider(ReceptionProvider):<br>  def provide(container_id: str) -&gt; None:<br>    MercadonaFishContainerService().call(container_id)</pre><p>And then inject one or another into our view:</p><pre>class ReceptionContainerView(APIView):<br>  def post(self, request, uid: str):<br>    container = ContainerRepository().retrieve_by_uid(Uid(uid))<br><br>    if container.is_fish():<br>      ReceptionContainer(MercadonaFishReceptionService()).execute(container.internal_id)<br>      return Response(status=200)<br><br>    ReceptionContainer(MercadonaReceptionService()).execute(container.internal_id)<br>    return Response(status=200)</pre><p>And that’s it! Here, we have applied our strategy pattern. But in reality, we like having our views and our actions as clean as possible, so what we usually do is put this logic <strong>inside the provider</strong>, and the final result would look like this (although with this, we are “corrupting” the pattern):</p><pre>class ReceptionContainerView(APIView):<br>  def post(self, request, uid: str):<br>    ReceptionContainer(MercadonaReceptionProvider()).execute(Uid(uid))<br>    return Response(status=200)</pre><pre>class ReceptionContainer:<br>  def __init__(self, reception_provider: ReceptionProvider):<br>    this._reception_provider = reception_provider<br><br>  def execute(self, container_uid: Uid) -&gt; None:<br>    self._reception_provider.provide(container_uid)</pre><pre>class MercadonaReceptionProvider(ReceptionProvider):<br>  def provide(container_uid: Uid) -&gt; None:<br>    container = ContainerRepository().retrieve_by_uid(uid)<br>    <br>    if container.is_fish():<br>      return MercadonaFishContainerService().call(container.internal_id)<br>    <br>    return MercadonaContainerService().call(container.internal_id)</pre><p>And now, what’s the point of using a provider for this? Well, as you can see, in the end, we have been able to leave our view and our action clean, <strong>separating the code</strong> into classes that <strong>only do what they have to do</strong>. We have <strong>decoupled our action code</strong> from the specific implementations of the external services, and in the future, if something external changes, we just have to change our provider.</p><p>Typically, we inject the repo into the action, and the provider’s contract would be a Container (domain) object. This setup allows us to encapsulate the logic within the action, while the provider handles the external services. The overall structure would look like this:</p><pre>class ReceptionContainerView(APIView):<br>  def post(self, request, uid: str):<br>    ReceptionContainer(DjangoContainerRepo(), MercadonaReceptionProvider()).execute(Uid(uid))<br>    return Response(status=200)</pre><pre>class ReceptionContainer:<br>  def __init__(self, container_repo: ContainerRepo, reception_provider: ReceptionProvider):<br>    this._container_repo = container_repo<br>    this._reception_provider = reception_provider<br><br>  def execute(self, container_uid: Uid) -&gt; None:<br>    container = self._container_repo.retrieve_by_uid(uid)<br>    self._reception_provider.provide(container)</pre><pre>class MercadonaReceptionProvider(ReceptionProvider):<br>  def provide(container: Container) -&gt; None:    <br>    if container.is_fish():<br>      return MercadonaFishContainerService().call(container.internal_id)<br>    <br>    return MercadonaContainerService().call(container.internal_id)</pre><p>My favorite part about this is that decoupling and separating our code <strong>greatly simplifies our testing </strong>because now we don’t have to test our external services inside our action tests.</p><p>We usually have:</p><ul><li>A happy path integration test in the view (mocking only the external services calls)</li><li>All the business logic tests inside the action (mocking the injected classes)</li><li>The database tests inside the repository</li><li>The external services tests with their logic inside the provider implementation tests</li></ul><p>I think that’s all, folks 😄; actually our use cases are a bit more complex than this, and maybe with this example, we can’t see all the benefits of this type of programming, but I promise you, decoupling our code and following SOLID principles and cool tools like Hexagonal Architecture or DDD are really powerful talking about <strong>maintainability and readability</strong> of our code, and of course are <strong>pretty cool</strong> 😼</p><p>Thanks for your time. Any kind of feedback is welcome!</p><p>I hope I’ll see you in the next <a href="https://medium.com/p/1414555abe71/">chapter</a>! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ff3d49710b4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadona-tech/quick-design-patterns-series-1-the-strategy-pattern-4ff3d49710b4">Quick Design Patterns Series 1: The Strategy Pattern 🎯</a> was originally published in <a href="https://medium.com/mercadona-tech">Mercadona Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code review? No thanks ]]></title>
            <link>https://medium.com/mercadona-tech/code-review-no-thanks-5433c14e1b51?source=rss-fc4f2a8feca1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5433c14e1b51</guid>
            <category><![CDATA[code-review]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Felipe Álvarez]]></dc:creator>
            <pubDate>Tue, 05 Dec 2023 08:31:51 GMT</pubDate>
            <atom:updated>2023-12-05T08:31:51.903Z</atom:updated>
            <content:encoded><![CDATA[<p>Hi 👋, for giving a little bit of context, I’m a backend dev in the V6 vertical in Mercadona Tech. Our backend team comprises 3 amazing (and lazy) devs, and we are responsible of managing the dark part of our beloved product: the Stocks App. This app is used in the physical Mercadona stores to control the Stock (reception of trucks, count the stock, report breakages, make donations… and a lot more 😼)</p><p>If you want to know more about us, you can check these posts:</p><ul><li><a href="https://medium.com/mercadona-tech/our-bread-and-butter-42cf937bdaf8">General overview of our product</a></li><li><a href="https://medium.com/mercadona-tech/contract-tests-a-new-hope-e2df7470e118">Contract testing</a></li><li><a href="https://medium.com/mercadona-tech/implementing-multi-tenancy-in-a-production-system-df2f9710d1d">Multi-tenancy</a></li><li><a href="https://medium.com/mercadona-tech/observability-in-stocks-8fd7fb5c6a46">Observability</a></li></ul><p>Today, I was thinking about the fact that we don’t put more description or info in our PR’s than some random GIF and a name for the final commit (we use squash merge, and every PR that we make finally converts in one commit to our main branch)</p><p>If you don’t believe me, I promise that 95% of our PR’s look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Yb5stPvYtJnNxgn4kIJPVw.png" /></figure><h3>But how can we work properly without explaining our code to our teammates? 🤯</h3><p>Well, I think this is because some factors combined:</p><h3>Small PR’s</h3><p>We try to make our PR’s as tiny as possible. They are easier to read, easier to make (and faster to merge), easier to review, easier to rollback… do you need more advantages?</p><p>It’s like the first SOLID principle: do one thing. If you make a little change in your codebase, just make one PR for it! (If you usually make significant changes in your codebase, maybe the problem comes because of your slicing).</p><p>This is one of the best things we do, and because every time we merge one PR to master it goes directly to PROD (<a href="https://medium.com/mercadona-tech/continuous-deployment-how-to-enhance-the-quality-of-our-products-1a4db6e50179">here</a> you can understand why we do this), if it fails, we can easily detect what was the cause, because it’s a small PR, with small changes, and a small piece of code.</p><h3>Slicing together</h3><p>Well, a part from the slicing of the tasks that we do every sprint with the rest of the team (product, design, natives…), we also slice every task in backend together.</p><p>Before starting every task, we take our time to talk and discuss how are we going to do it, define our subtasks and some times even the naming! We define how we want to do it and then we make them together or we split up if they are really easy or mechanic.</p><h3>Communication</h3><p>It’s not only the slicing, we usually work together in person from Monday to Thursday (and we take Fridays as remote hehe), but, even if we are in person or in remote, we maintain a good communication while we are coding.</p><p>If we have some doubt in the process (how we will test some code, what is the best naming for a provider or variable, how can we refactor some method, or whatever we aren’t sure about), we just ask our teammates! In that case, we take our time one more time to talk and define what we are doing and why.</p><h3>Pairing</h3><p>I think this is the most important thing for us. It’s very similar to the point above. Our communication improves a lot more if we are doing pair programming!</p><p>It also has a lot of benefits, like helping us to learn and share knowledge, and also to code better and faster, and with less errors or misconceptions. We code almost everything in pairing, and our bounds are stronger than ever 🫂</p><h3>I don’t understand this, show me the code</h3><p>Usually, we code in pairs, and therefore, we don’t even need a review for our PR’s because we have already done them together, but sometimes we code alone, and then we ask our teammates to review that PR.</p><p>Usually (and because we have done all the other things I explained before), the review is just an “ok, I like that,” but other times, we doubt the changes.</p><p>But this is not a problem! We take our time to review the PR together and discuss the changes, and maybe it’s just an explanation, or perhaps we finally end up doing some refactoring or changes on it (and because we all know about the problem and it’s a small change, it’s not challenging to modify things in them, and it’s also really fast 😎)</p><h3>Feature Flags</h3><p>Another thing that we use is Feature Flags. This is one of the keys for us to deploy to PROD quickly. I have an article explaining this <a href="https://medium.com/mercadona-tech/how-we-manage-feature-flags-f1641d0671c2">here</a>.</p><h3>Test everything</h3><p>Of course, we test everything and have our nice, clean, and cool tests to reflect every change we make or add to our codebase (you can see why we do this <a href="https://medium.com/mercadona-tech/crafting-clean-tests-851dc0e4b1a">here</a>.</p><p>We take our time and effort to keep our tests clean and understandable, which helps us understand our code and PR’s because usually, one change comes with a new test that explains perfectly what we have done.</p><h3>Conventions</h3><p>We are quite a mature team and have a lot of knowledge about our product and project. Over time, we have made some conventions that every one of us understands and knows, which helps us with our code development.</p><p>These conventions change a lot while we learn new things or think about how we want to structure and create our code.</p><p>These are conventions about how we test our modules, how we name our things, when and why we use factories, builders, inject dependencies, use providers, where to put our files inside our repo, and so on; you know all the things that I mean 😉</p><h3>But yes, we have some info in our PR’s</h3><p>As you can see in the first image, we try to put a good name that describes the final commit, and we also have the changed, added, fixed, removed, deprecated, and security tags. We add this to every PR to easily find them when checking some old code.</p><p>Last but not least, we also added the Jira reference to the ticket we are working on in case we want to see the User Story in the future (and find some possible explanation about why we did that).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*inCRqwkHGMLaeG9zrzM-lw.png" /></figure><h3>All of this is so cool but… is it really worth it?</h3><p>Well, I am not going to try to convince you that this is the way to do things, and thanks to being a data-driven company, I’ll show you some data and metrics of our results in the backend for our last month, October of 2023:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gS1GGaO_W4PvmnaV5YJDgA.png" /><figcaption>Incidents caused</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nSIpI17dGuTUm3-iTIL8jA.png" /><figcaption>Deployments per month</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q1yeP1uiJz4QSwrcKWMEvg.png" /><figcaption>Time of our branches &amp; time to deploy</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3Afl3BgBEaP3ReF2U_50Bg.png" /><figcaption>Deployments to PROD by week day</figcaption></figure><p>In summary, you can end up with things like this when you put together all of these practices (I know it’s hard, and it usually comes with a strong company culture). I think not having to comment on your PR’s is pretty similar to not having to comment on your code because you have done many things before that make everything easier (apply SOLID principles to everything in your life 😉).</p><p>As you can imagine, this has not always been like this. We have been learning a lot along the way and improving everything we could, always trying to work better together, and we have much more to learn!</p><p>So… yeah, I’m very proud of us, and I think we are correctly doing things (I also know that we have a lot of things to improve).</p><p>Of course, this is working for us because of our team conditions (we are only 3 backends, and it’s easy to apply all of these things), and maybe with bigger teams or another structure, it is not so easy to use. This is not the ultimate truth on how to do things, and it’s just a way that, at least for us, works pretty well 🙂</p><p>Last, this is happening because there is a lot of hard work and effort behind it, just say thanks to my team for making this possible. I know there is still a lot to come!! 💚</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5433c14e1b51" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadona-tech/code-review-no-thanks-5433c14e1b51">Code review? No thanks 🙅</a> was originally published in <a href="https://medium.com/mercadona-tech">Mercadona Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we manage Feature Flags ]]></title>
            <link>https://medium.com/mercadona-tech/how-we-manage-feature-flags-f1641d0671c2?source=rss-fc4f2a8feca1------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1641d0671c2</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-testing]]></category>
            <category><![CDATA[feature-flags]]></category>
            <dc:creator><![CDATA[Felipe Álvarez]]></dc:creator>
            <pubDate>Fri, 21 Jul 2023 09:08:13 GMT</pubDate>
            <atom:updated>2023-07-21T09:08:13.869Z</atom:updated>
            <content:encoded><![CDATA[<h3>Intro</h3><p>Hi everyone! The purpose of this post is to provide a brief explanation of how we typically manage feature flags on our team. This includes adding them to code and tests, as well as the most important aspect: deleting them in the easiest way possible to avoid errors</p><p>We are really lazy programmers that don’t like thinking too much, and therefore we always try to simplify our work in a way that helps us to focus on the important things and avoid losing our time and energy on minor details</p><p>I will demonstrate this with an example of simplified code (in the real world, we make some intermediate steps due to the use of TDD) 💻</p><h3>The problem</h3><p>Let’s put a little bit of context. Think about we have to make a change inside one of our use cases. As usually, we want to add a feature flag that controls that change (we use FFs to everything, i mean EVERYTHING)</p><p>Okay, so we want to change, for example, a filter in one of our actions that only retrieves some info of our database, how we start?</p><h3>The action</h3><p>We have our action like this:</p><pre>class RetrieveStuff:<br>  def execute(self, name: str) -&gt; Stuff:<br>    return Stuff.objects.filter(name=name).first()</pre><p>First we refactor it’s name, adding the suffix Old, and then we add our new action:</p><pre>class RetrieveStuffOld:<br>  def execute(self, name: str) -&gt; Stuff:<br>    return Stuff.objects.filter(name=name).first()<br><br>class RetrieveStuff:<br>  def execute(self, name: str) -&gt; Stuff:<br>    return Stuff.objects.filter(name=name, is_active=True).first()</pre><h3>The action tests</h3><p>Here we follow the same approach that we have follow with the action. First we have our tests (now with the refactored name that we did before):</p><pre>class TestRetrieveStuffOld:<br>  def test_retrieve_stuff_by_name(self):<br>    Stuff.objects.create(name=&quot;a_name&quot;)<br>  <br>    stuff: Stuff = RetrieveStuffOld().execute(&quot;a_name&quot;)<br>  <br>    assert stuff.name == &quot;a_name&quot;</pre><p>And then, we duplicate the tests for the new action and make the changes we need:</p><pre>class TestRetrieveStuffOld:<br>  def test_retrieve_stuff_by_name(self):<br>    Stuff.objects.create(name=&quot;a_name&quot;, is_active=False)<br><br>    stuff: Stuff = RetrieveStuffOld().execute(&quot;a_name&quot;)<br><br>    assert stuff.name == &quot;a_name&quot;<br><br><br>class TestRetrieveStuff:<br><br>  def test_retrieve_stuff_by_name_and_active(self):<br>    Stuff.objects.create(name=&quot;a_name&quot;, is_active=True)<br><br>    stuff: Stuff = RetrieveStuff().execute(&quot;a_name&quot;)<br><br>    assert stuff.name == &quot;a_name&quot;<br>    assert stuff.is_active</pre><h3>Adding it</h3><p>Okay, so now, we have our new action prepared and tested, but we are not using it, because our view (our infra enter point to the actions) should have this look:</p><pre>class RetrieveStuffView(APIView):<br>  def get(self, name: str):<br>    stuff: Stuff = RetrieveStuffOld().execute(name)<br>    <br>    return Response(data=StuffSerializer(stuff).data)</pre><p>What we usually do at this point is making a PR and deploy to PROD 🚀</p><p>Then, it’s time to add the FF into our view:</p><pre>class RetrieveStuffView(APIView):<br>  def get(self, name: str):<br>    if not flags.is_active(&quot;use-new-filter-for-stuff&quot;):<br>      stuff: Stuff = RetrieveStuffOld().execute(name)<br>      <br>      return Response(data=StuffSerializer(stuff).data)<br>    <br>    stuff: Stuff = RetrieveStuff().execute(name)<br>    <br>    return Response(data=StuffSerializer(stuff).data)</pre><p>Note that we add it with a not statement, this will help us to not thinking later when we have to delete it. We will explain this later</p><h3>The view tests</h3><p>Here is much more the same as the action tests. We have our view tests, and then we duplicate them, adding a fixture to enable or disable the flag for each test class:</p><pre>class TestRetrieveStuffViewWhenFlagDisabled:<br>  <br>  @pytest.fixture(autouse=True)<br>  def manage_flag(self, activate_flag):<br>    activate_flag(&quot;use-new-filter-for-stuff&quot;, False)<br><br>  def test_retrieve_stuff_by_name(self, client):<br>    response = client.get(&quot;/api/stuff/a_name/&quot;)<br><br>    assert response.status_code == 200<br>    assert response.json() == {<br>      &quot;name&quot;: &quot;a_name&quot;,<br>      &quot;is_active&quot;: False,<br>    }<br><br><br><br>class TestRetrieveStuffView:<br><br>  @pytest.fixture(autouse=True)<br>  def manage_flag(self, activate_flag):<br>    activate_flag(&quot;use-new-filter-for-stuff&quot;, True)<br><br>  def test_retrieve_stuff_by_name_and_active(self, client):<br>    response = client.get(&quot;/api/stuff/a_name/&quot;)<br><br>    assert response.status_code == 200<br>    assert response.json() == {<br>      &quot;name&quot;: &quot;a_name&quot;,<br>      &quot;is_active&quot;: True,<br>    }<br></pre><p>Nice! Now we can make another PR with this code, create and activate the FF in our systems and start using the new functionality in our production environments 🤘</p><h3>Deleting it</h3><p>This is, for me, the better part. We usually do this after 2 days of having deployed the new code in PROD (or after we think the new code is 100% validated)</p><p>Thanks to the fact that everything has been duplicated, we can now remove this FF and the old code without hesitation. It’s as simple as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*3a8PoTZABKZ9uB62810w0A.png" /><figcaption>The view</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*_isLjGCos5DO_sEQQ5aqbw.png" /><figcaption>The action</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/691/1*R7pMZgud6ZSlKpqRU9T7Xg.png" /><figcaption>The view tests</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/699/1*H9ctecWYjil0hnhp9y5ysA.png" /><figcaption>The action tests</figcaption></figure><p>And that’s it! We just need to remove everything that have the suffix Old or WhenFlagDisabled, without thinking about ifs, tests, or complicated paths</p><h3>Conclusions</h3><p>Maybe you can think that this approach of development produces a lot of duplicated and redundant code (and you are right 🙄), but it’s for a really short period of time. We think that the advantages that this approach give us:</p><ul><li>An easier development</li><li>Have our 2 paths perfectly separated, including the tests</li><li>A really easy and fast process of removing the old code</li><li>Reduce the human errors inserting the new code or testing it</li></ul><p>Are very worthwhile compared to insert the flags inside and mixed with our production code. I encourage you to try it, believe me, no one will charge you for uploading more code lines to your repo 😉</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1641d0671c2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadona-tech/how-we-manage-feature-flags-f1641d0671c2">How we manage Feature Flags 🚀</a> was originally published in <a href="https://medium.com/mercadona-tech">Mercadona Tech</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>