<?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 Konstantin Maliuga on Medium]]></title>
        <description><![CDATA[Stories by Konstantin Maliuga on Medium]]></description>
        <link>https://medium.com/@konstantin.maliuga?source=rss-dfdab67bba90------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tJCf948SkxujlCXaqaxamw.jpeg</url>
            <title>Stories by Konstantin Maliuga on Medium</title>
            <link>https://medium.com/@konstantin.maliuga?source=rss-dfdab67bba90------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:51:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@konstantin.maliuga/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 Keep Distributed Systems Consistent: Versioning vs Vector Clocks]]></title>
            <link>https://levelup.gitconnected.com/how-to-keep-distributed-systems-consistent-versioning-vs-vector-clocks-e35b407e7193?source=rss-dfdab67bba90------2</link>
            <guid isPermaLink="false">https://medium.com/p/e35b407e7193</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[consistency]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Konstantin Maliuga]]></dc:creator>
            <pubDate>Mon, 14 Apr 2025 00:34:30 GMT</pubDate>
            <atom:updated>2025-04-14T08:07:58.902Z</atom:updated>
            <content:encoded><![CDATA[<p>When a single service handles all updates, ensuring data consistency is relatively straightforward: updates happen in a well-defined order, and there’s no ambiguity about state. But as systems scale and processing is distributed across threads, services or entire regions, guaranteeing that every component agrees on “what happened, and in what order” becomes a much harder challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-dC2MFS_87VwG-M3U5j43w.png" /></figure><p>This is where tools like <strong>versioning</strong> and <strong>vector clocks</strong> come into play. Whilst both track changes over time, they serve very different roles in preserving consistency. Understanding their differences and applying them in the right context can help to scale systems without sacrificing correctness or reliability.</p><h3>Versioning: A Simple Mechanism for Distributed Consistency</h3><p>Versioning is about tracking changes. Whether it’s a document, a record, or a software component, versioning helps us know what changed, when, and what version we’re working with. It comes in several forms, each suited to different contexts:</p><ul><li><strong>Monotonic numbers</strong> (e.g., version = 1, 2, 3...) are simple counters that increase with each update. They&#39;re widely used in databases and messaging systems to maintain order of operations.</li><li><strong>Timestamps</strong> (updated_at) are often used to record when something changed. They&#39;re easy to generate and useful for auditing and monitoring.</li><li><strong>Hashes</strong> (like Git commit SHAs) uniquely identify the content of a file or object based on its data. They’re commonly used in systems where integrity and immutability are important, like version control or distributed file systems.</li><li><strong>Semantic versioning</strong> (v1.2.3) is designed to convey the nature and impact of changes in a clear, predictable way—particularly important when managing dependencies between components or services.</li></ul><p>Each of these versioning types plays a role in helping systems reason about change. Let’s see how some of them can be used for conflict detection or ordering in distributed environments.</p><p>There are two situations when versioning can help with parallel processing whilst maintaining consistency:</p><ul><li><strong>Optimistic locking</strong>, when organising writes from multiple sources without losing concurrent updates,</li><li><strong>Event processing or projections</strong>, when reacting to changes or building a custom representation from them, to ensure all these changes are applied the correct order.</li></ul><h3>Optimistic locking</h3><p>Imagine a system that updates account balances. There can be multiple application instances handling balance update requests that should be applied in a database (the database can actually be a set of shards that store a subset of accounts, but it’s not the point).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QtudPogIIppTb_ATd-VZ6g.png" /><figcaption>Application instances receive update requests, and after applying domain logic store changes in DB(s)</figcaption></figure><p>It’s a fairly scalable setup, but handling concurrent updates safely becomes crucial: what if balance updates to the same account are received in parallel on different nodes/threads. Then, if both requests are valid, one change should not overwrite the other. Otherwise, if only one of the changes can be applied (e.g. if having both operations would lead to overdraft) then one of the operations should fail consistently.</p><p>The traditional approach to preventing conflicting updates is <strong>pessimistic locking</strong>, which blocks the data until a transaction is finished:</p><pre>BEGIN;<br>SELECT * FROM accounts WHERE id = 123 FOR UPDATE;<br>-- account 123 cannot be updated until the transaction is committed/rolled back- do verifications + calculations on the app side<br><br>UPDATE accounts SET balance = 100 WHERE id = 123;<br>COMMIT;</pre><p>ℹ️ Before we continue, it’s worth noting that in the examples we directly set the account balance (balance = 100). Of course, in such cases deltas could be applied instead: incrementing or decrementing the balance by a certain amount. However, not all data models support additive updates, and direct assignment can be a useful abstraction for any state mutation where merge logic is non-trivial.</p><p>The row locking above guarantees that no other transaction can update the row until the current one is complete. It’s safe — but not cheap. Locks can lead to several issues that degrade performance:</p><ul><li><strong>Overhead</strong>: The database must track and manage lock state, which increases CPU and memory usage, especially under high concurrency.</li><li><strong>Deadlocks</strong>: If two transactions each hold a lock and wait for the other’s resource, the system can deadlock, requiring a rollback of one transaction.</li><li><strong>Reduced parallelism granularity</strong>: While one transaction holds a lock, others are blocked (even if their operations could safely proceed) limiting system throughput and concurrency.</li></ul><p>To avoid these performance penalties, many systems instead use <strong>optimistic locking</strong>. Rather than locking rows, the application checks that the data hasn’t changed since it was last read before attempting to write.</p><p>Let’s start with a common approach using timestamps.</p><p>One application instance reads the account first:</p><pre>SELECT <br>  balance,     -- 0<br>  updated_date -- &#39;2024-01-01T12:00:00Z&#39;<br>FROM accounts <br>WHERE id = 123;</pre><p>It does some processing, then issues an update based on the updated_date it observed:</p><pre>UPDATE accounts<br>SET <br>  balance = 100, <br>  updated_date = &#39;2025-02-02T02:00:00Z&#39; -- current time<br>WHERE id = 123 AND updated_date = &#39;2024-01-01T01:00:00Z&#39;;</pre><p>This will only apply if no one else changed the row in the meantime, because the WHERE clause ensures the update is executed only if the original updated_date matches, effectively acting as a lightweight consistency check without locking.</p><p>This mechanism can be extended across multiple operations in a single transaction. After each UPDATE, the application checks how many rows were affected. If all expected changes are applied successfully, the transaction can safely commit. But if even one update is skipped (due to a mismatch in the updated_date), the application can roll back the entire transaction to avoid leaving the system in a partial state.</p><pre>BEGIN;<br><br>UPDATE accounts<br>SET balance = 100, updated_date = &#39;2025-02-02T02:00:00Z&#39;<br>WHERE id = 123 AND updated_date = &#39;2024-01-01T01:00:00Z&#39;;<br>-- Check how many rows were updated. If 0, rollback<br><br>UPDATE transfers<br>SET status = &#39;COMPLETED&#39;, updated_date = &#39;2025-02-02T02:00:00Z&#39;<br>WHERE transaction_id = &#39;txn-789&#39; AND updated_date = &#39;2024-01-01T01:00:00Z&#39;;<br>-- Check how many rows were updated. If 0, rollback<br><br>COMMIT;</pre><p>This approach tends to be efficient at scale, particularly when contention on individual records is low: a big number of accounts are being updated concurrently but independently. In such scenarios, optimistic locking ensures consistency without triggering frequent rollbacks or retries, because it’s rare for multiple processes to target the same record at the same time.</p><p>⚠️But here’s the catch when using timestamps for this approach. If the updated_date is set explicitly by the application (rather than relying on the database&#39;s NOW() or equivalent), then it can be affected by <a href="https://en.wikipedia.org/wiki/Clock_drift"><strong>clock drift</strong></a> between instances. For example, if one instance&#39;s clock is slightly behind, it might set the new updated_date to a value that matches the current one in the database. Then, if another instance concurrently updates the row with a slightly more recent timestamp, it can silently override the earlier change.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WRc8F3AUlXd0xzLXdok79Q.png" /><figcaption>Instances 2 and 3 can read the account state stored by 1 at the same time. And then 3 can accidentally overwrite the update of 2, if 2 stored the account with the same updated_date as it was due to clock drift</figcaption></figure><p>This kind of race condition leads to <strong>undetected data loss</strong>, as the timestamp no longer guarantees a clear “happened-before” relationship between changes.</p><p>To avoid this, either the database should be responsible for setting the timestamp (e.g., using NOW() or CURRENT_TIMESTAMP) to ensure consistency across updates, or systems should use a <strong>sequential version number</strong>:</p><pre>UPDATE accounts<br>SET balance = 100, version = 6<br>WHERE id = 123 AND version = 5;</pre><p>If someone else already updated the row and bumped the version to 6, the current update won’t apply. The system can re-fetch the latest state, reassess the logic, and retry with the new version.</p><p>Sequential versions avoid clock drift issues and make the intent explicit: every update must be based on the known previous state, and if anything changed in the meantime, new writes will always be rejected.</p><h3>Event Processing and Projections</h3><p>Versioning also helps when reacting to changes in different parts of a distributed system or building <strong>projections</strong> (read-optimised views built from write-focused data structures).</p><p>Let’s say we track accounts with assigned currencies: when a user opens an <strong>Account</strong> — the system needs to track which currencies are associated with the user. This can be useful for triggering notifications specific to currency holders.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2yCenvjGFfs4nZ49nO8ejw.png" /><figcaption>The user_currencies projection with relevant account currencies is built from event of accounts that are currently opened</figcaption></figure><p>The projection building service might receive the following events: AccountOpened{user,currency} and AccountClosed{user,currency}.</p><p>To improve processing throughput, multiple application instances process these events in parallel, as events related to the same user or account are relatively rare. This processing parallelisation reduces latency for the updates queue and increases system scalability.</p><p>We’ll look at how the system might process a case when a user opened and closed an account in a short period of time, producing the following:</p><ol><li>AccountOpened{user:101,currency:GBP}</li><li>AccountClosed{user:101,currency:GBP}</li></ol><p>If there’s any delay in delivering the first event, this sequence can lead to a problem: the projection could incorrectly reflect that the account was closed when it was never opened. This leads to an invalid domain state.</p><p>To resolve this, we introduce a sequential version number in the event payload:</p><ol><li>AccountClosed{user:101,currency:GBP,version:3}</li><li>AccountOpened{user:101,currency:GBP,version:3}</li></ol><p>When the projection logic encounters the version: 3 event, it checks whether it is the next expected version to process, in this case version: 2. Since it recognises that the event has arrived out of order, it is <strong>postponed</strong> and requeued for future reprocessing.</p><p>Sequential version numbers are again preferred here in comparison with timestamps. Imagine you’re processing balance update events for an account, and each event carries a delta:</p><ol><li>BalanceUpdated{user:101,date:&quot;00-01&quot;,amount:+£100}</li><li>BalanceUpdated{user:101,date:&quot;00-02&quot;,amount:+£50}</li><li>BalanceUpdated{user:101,date:&quot;00-03&quot;,amount:-£20}</li></ol><p>If the third event arrives first and gets applied to an initial balance of £0, the projection might incorrectly show a balance of -£20, since all the other events from before will be rejected: there&#39;s just <strong>no reliable way to detect</strong> that two earlier updates are missing, because the timestamp doesn&#39;t indicate sequence.</p><p>In some cases, like simple view projections, it might be possible to include the final state directly in the event payload (such as the total balance after applying the update). That way, even if earlier deltas are missed, the projection can eventually still be corrected to reflect the final known value: BalanceUpdated{user:101,date:&quot;00:03&quot;,amount:-£20,total:130}.</p><p>However, if it’s essential to apply all intermediate steps as they were originally registered, missing events can’t simply be overwritten by the latest snapshot. Then using version number helps to immediately recognise that previous updates haven’t arrived yet. In the example above this enables the system to defer applying version 3 until the prior events are received and processed, preventing the projection from drifting into an invalid state.</p><h3>Vector Clocks: Making Sense of Concurrent Updates</h3><p>Versioning provides a great deal of help when <strong>there’s a single source of truth</strong>. One producer. One writer. What if updates come from multiple services e.g multiple regions? What if the sources are not even aware of each other?</p><p>In many distributed systems, multiple nodes can produce writes to the same data independently. And when they later sync up, the system needs to figure out what exactly happened.</p><p><strong>Vector clocks</strong> are one of the tools that help systems reconcile independently generated changes across distributed nodes.</p><p>Here’s how it works:</p><p>Each node maintains a counter representing the number of updates it has performed. It also tracks what it knows about other nodes’ counters. Let’s look at a setup with three nodes:</p><ul><li>Node A: {A: 2, B: 0, C: 0} — it has made 2 updates and has seen none from B or C.</li><li>Node B: {A: 0, B: 1, C: 0} — it has made 1 update and has seen none from A or C.</li><li>Node C: {A: 0, B: 0, C: 3} — it has made 3 updates independently.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zoP2_XZR16DfjeEVZrlGtg.png" /><figcaption>Nodes A, B and C can be updated independently until vector clocks are compared to spot conflicting updates and merge changes</figcaption></figure><p>When these nodes synchronise, they compare their vector clocks with others and merge updates.</p><p>After synchronisation, all nodes will incorporate the updates from the others:</p><ul><li>Node A: {A: 2, B: 1, C: 3}</li><li>Node B: {A: 2, B: 1, C: 3}</li><li>Node C: {A: 2, B: 1, C: 3}</li></ul><p>This reflects a fully synchronised state, where each node has applied all the updates performed across the cluster.</p><p>If updates happened concurrently on multiple nodes, the clocks will help determine whether nodes had seen each other’s changes at the time, and those changes are considered <strong>concurrent updates</strong>, for which conflict resolution strategies must be applied.</p><h4>Balance reconciliation</h4><p>Let’s take an example, looking at a system that processes balance updates from a third-party that we’ll call <strong>WISA</strong>. For simplicity it will be only two nodes (A&amp;B) that process transactions involving WISA and both of those are initially synchronised with balance on WISA account equal to £1:</p><ul><li>Node A: {A: 2, B: 1}</li><li>Node B: {A: 2, B: 1}</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FA0siQ3fwBQj-sRMMzh6cA.png" /><figcaption>Nodes A and B process external updates independently and synchronise their state periodically</figcaption></figure><p>There are a few updates processed on these nodes at the same time:</p><ul><li>A processes +£2, then -£1. A’s clock: {A: 4, B: 1}. Balance = £2</li><li>B processes +£4. B’s clock: {A: 2, B: 2}. Balance = £5</li></ul><p>When they sync, both apply each other’s updates: A applies update 2(+£4) from B, and B applies updates 3(+£2) and 4(-£1) from A. The final balance becomes synchronised on each node: £6, and clock become synchronised on each node: {A: 4, B: 2}. If a new node C is added to the system then either A or B would exchange their vector clock with it, allowing C to quickly catch up to the consistent state of the cluster.</p><p>The vector clocks for WISA might also change on other operations, such as communication log with the third party, a number of corrections etc. In all these cases conflicts resolution works failry straightforward, since these changes are still <strong>mergeable</strong>. Vector clocks help detect when updates conflict, allowing the system to apply the appropriate resolution strategy.</p><p>If it is not possible to simply merge data, vector clocks conflicts can be solved with alternative strategies:</p><ul><li><strong>Last Write Wins</strong>, which should be considered if updates loss is acceptable.</li><li><strong>Domain-specific logic</strong>, such as preferring updates with a higher priority, monetary value, or based on contextual business rules.</li><li><strong>Manual resolution</strong>, where both versions are returned and the application or user chooses the correct one.</li></ul><p>Ultimately, vector clocks surface the conflict, but your domain defines how to resolve it.</p><h3>The Takeaway</h3><p>Versioning and vector clocks are both essential tools in distributed systems, but they serve different purposes:</p><ul><li><strong>Versioning</strong> is ideal when changes originate from a single source. It provides a simple, effective way to ensure reliable concurrency control and maintain ordered event processing for things like projections and reactions.</li><li><strong>Vector clocks</strong> can be helpful when multiple nodes can generate updates independently. They help detect concurrency and offer a way to reconcile divergent states across distributed actors.</li></ul><p>Used appropriately, both tools can help systems scale while preserving data consistency, even in highly concurrent, distributed environments.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e35b407e7193" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-keep-distributed-systems-consistent-versioning-vs-vector-clocks-e35b407e7193">How to Keep Distributed Systems Consistent: Versioning vs Vector Clocks</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Best Code is the Code You Don’t Write: Avoiding Overcomplication in Critical Systems]]></title>
            <link>https://levelup.gitconnected.com/the-best-code-is-the-code-you-dont-write-avoiding-overcomplication-in-critical-systems-0044fbe55fd8?source=rss-dfdab67bba90------2</link>
            <guid isPermaLink="false">https://medium.com/p/0044fbe55fd8</guid>
            <category><![CDATA[problem-solving]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[leadership]]></category>
            <category><![CDATA[prioritization]]></category>
            <category><![CDATA[best-practices-technology]]></category>
            <dc:creator><![CDATA[Konstantin Maliuga]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 01:30:22 GMT</pubDate>
            <atom:updated>2025-03-07T01:30:22.470Z</atom:updated>
            <content:encoded><![CDATA[<p>Imagine building a bridge to cross a puddle. Engineers would laugh, but in software we do this daily. Teams often rush to solve problems using code before questioning whether the problem <em>needs</em> solving or if it’s even the <em>right</em> problem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHIN_IXdNdFhQewyFpIaGQ.png" /><figcaption>A bridge over a body of water always makes sense, doesn&#39;t it?</figcaption></figure><p>In critical systems — like banking, healthcare, or infrastructure — unnecessary code isn’t just clutter. It’s a risk. Every new line is a potential bug, maintenance burden, and complexity. Sometimes it can even create new problems that further distract from the original goal.</p><p><em>The best solutions often start with questioning the problem itself. Sometimes, the right answer is to write no code at all.</em></p><h3>The Cost of Unnecessary Code</h3><p>Prototyping and writing code is fun and easy. Maintaining it can become a difficult chore. Let’s go through some of the potential problems that can be caused by the introduction of new application logic when developers are too eager to jump to implementation:</p><h4>Complexity growth</h4><p>Every new line of code added increases the complexity of the system. Usually it’s not a dramatic change, but complexity tends to stack up: one line in a new project does one clear thing, but in an existing code base it might interact with different context variables, depending on the quality of the code. Then how easy will it be for a new person in a project to understand all these interactions? How many context variables should be kept in one’s head to prevent introduction of a bug? Essentially, every new piece of logic is something we might have to consider tomorrow in addition to the already existing complexity of it.</p><p>There are good practices for keeping both essential (domain) and accidental (engineering) complexity in check (e.g. DDD, Hexagonal architecture, simple abstractions etc.). But they still require knowledge and effort to maintain simplicity of the context when making changes, and then revisiting and further simplification when domain matures or pressing deadlines are met.</p><h4>Opportunity Cost</h4><p>Adding new logic is not only the fun of code writing, that can take between five minutes to N days, it’s also impact analysis, testing, deployment, potential iterations and communication. If we are busy with this, we don’t do something else.</p><h4>Risk Amplification</h4><p>New code changes = new risks. It’s obvious that logic changes might introduce bugs: the new logic might not work as developer intended, or the existing flows can become broken,. Other sorts of things can happen as well: a compliance gap introduced, performance bottleneck created, or a new attack vector emerged. In any case sometime changes bring more harm than good.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_sMD0hLAlg83AVaovoEEKQ.png" /><figcaption>Always adding more when solving problems can become a problem in itself</figcaption></figure><h3>How Exactly Do We Overcomplicate</h3><p>Software engineers are problem-solvers by nature, but it’s a double edged sword sometimes. Especially when we don’t take time to reflect on what we do.</p><p>More often than wanted, engineers are <strong>solving symptoms, not root causes</strong>. It happens especially often when teams or individuals are handed a task, and they jump right to the solution.</p><p>An example of this could be a system that was sending emails to users when certain changes in their accounts were made. A problem was identified when developers realised that not only can users make these changes, but internal systems can too. This resulted in users receiving confusing emails saying “…if you didn’t make this change then contact us…”, when they certainly didn’t and that was expected. Fine, “let’s filter out changes, requested by users from changes made by systems” the team said. Sounds logical, but requires changes in a few places across a number of the components — for better agent tracking and then for notifications.</p><p>But what is the actual problem that had to be solved: do we want to provide nice emails, or do we want to prevent unauthorised access? What if instead of working on the emails, which are sent when it’s already too late, we start using the already available APIs to perform additional 2FA in the account changes flow, making sure it’s the actual owner who makes changes. It’s solved the actual problem and turned out to be much easier to do.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*naFklzVtnu1xkFeXysjjDQ.png" /><figcaption>Notifying customers after the problem occurs — can we prevent it instead?</figcaption></figure><p>Not only might the problem be misidentified. Oftentimes it’s the way to approach the problem. <strong>The first solution that engineers come up with often becomes their favourite,</strong> and then they start building. We then fell in love with this plan, especially when it’s not obvious. “It’s going to solve the problem in a such smart way!” we think.</p><p>Let’s say we need to decide on switching between synchronous and asynchronous processing for updates to a certain object stored in a DB. Too often synchronous updates lead to high contention that we are trying to avoid.</p><p>So the first idea that comes to mind is to switch to asynchronous processing when the rate of updates is too high — let’s track the rate then! We’ll set up a rate tracker. Then we’ll tune it. Well, the updates might come to different instances of our service, and we need to account for the scalability factor too… So, it has to be a distributed counter then, or the load balancer has to route based on custom ID specific logic.</p><p>What if we just step back before implementing anything. A rate tracker might be a good idea, but it requires configuring multiple parts and writing new code, hence intrinsically carries higher risk of bugs, higher time consumption etc. What if we start simple instead. What if we check the last updated_date timestamp on the object that we fetch from the DB in any way, and just enable async processing if the timestamp was updated too recently when the next update arrives. It’s a naive approach, but can be implemented with one line of code. It turned out that the naive approach was enough and prevented complicated and time consuming changes that the team wanted to jump to from the beginning.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6w3rnzC7031diz0ZeLaTsA.png" /><figcaption>A microscope is a usetool tool, but do we need to use it as a hammer if wealready have a hammer?</figcaption></figure><p>Lastly, as software engineers, we don’t always prioritise well. This is something where it’s always possible to learn something new and become bit better. But sometimes even with a known set of problems we are spending time on those that might be not the most important to focus on at the moment.</p><p>This one happened with me: I was designing sharding support in a set of existing services. And it was important to make sure the sharding approach is supported on a platform level, to be easily replicable in other services when becomes needed. It required considering a lot of different variables, and there were multiple potential ways to solve the problem. It was important to settle on sharding strategy, shard keys choice, on which level the implementation should reside etc. — something that Jeff Bezos calls one way door decisions [<a href="https://aws.amazon.com/executive-insights/content/how-amazon-defines-and-operationalizes-a-day-1-culture/">Amazon’s Day 1 culture — Make high quality, high velocity decisions</a>]; once settled it’s very hard to turn back. After solving some of these problems I also spent a few days providing the exact algorithm for partitions move between shards, even after making sure that it’s clearly possible, and that the way to do that is just a matter of implementation.</p><p>The problem was that we didn’t even need to move any partitions between shards any time soon, we needed a way to start writing to multiple PostgreSQL shards with our custom sharding strategy. But because this move would become needed at some point, and it was in the scope of the work of sharding, I easily forgot that time might be much more efficiently spent if I had switched to what was a priority in foreseeable future: other one way door decisions or even start building a POC to prove everything researched so far actually works together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wZa_A5nfJVP029dRai3DcA.jpeg" /><figcaption>To put out a cigarette or to tackle a house fire — both could be helpful, but the choice has to be made</figcaption></figure><h3>When to Write Code (and When Not To)</h3><p>We still need to code. New products and important changes won’t implement themselves. Then how to distinguish that it’s time to write code from when it’s not?</p><h4>Keep asking “Why?” until the problem cracks</h4><p>When tasked with solving a problem, dig deeper and try to understand the whole scope of it. As in the example of security emails sending on internal changes:</p><ul><li><em>“Why do we need to send these emails?”</em> → To react on unauthorized changes.</li><li><em>“Why do unauthorized changes happen?”</em> → Weak security checks.</li><li>Then let’s solve the root cause and improve the security checks, not just implement the surface ask.</li></ul><h4>Prioritise the right problems, think what happens if we don’t solve this problem now</h4><p>Not all problems are of equal importance. Some have a priority for clear reasons, others can wait, or their resolution is more expensive than the gained benefit.</p><p>During the sharding project, I prioritised data migration (a future problem for the time when other concerns are resolved) over validating the core ideas (a potential blocker for the whole project). Just thinking twice of what is a priority and what are the milestones to focus on would’ve helped to deliver the project quicker.</p><h4>Know your environment: can the problem be solved using the existing tools instead of building a new perfect instrument?</h4><p>This point is important especially for platforms and core systems. Building something ad-hoc is sometimes not only just opening loopholes, but also wastes time.</p><p>For the async processing example, the team nearly built a custom rate counter instead of relying on the already available updated_date timestamp. The result? The simple solution is working as perfect with almost no code changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9dOjFdaDKVpNsfj5XM0toQ.png" /><figcaption>Let&#39;s fully understand the problem and solve accordingly</figcaption></figure><h3>Less Code (that we don’t need), Better Systems</h3><p>Someone might read all this and say “well, if we don’t react quickly then we become slow and eventually lose competition with other companies on the market”. And I would even agree, if such quick actions were always applied in the right direction, were well justified means and sometimes wouldn’t bring more problems than benefits.</p><p>So to be quick and efficient, let’s just make sure that when approaching a problem, before jumping to coding, we can fully understand exactly why it should be solved, why doing this is more important than working on something else, and whether the way to resolve this problem is optimal.</p><p>Because sometimes less is more.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0044fbe55fd8" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/the-best-code-is-the-code-you-dont-write-avoiding-overcomplication-in-critical-systems-0044fbe55fd8">The Best Code is the Code You Don’t Write: Avoiding Overcomplication in Critical Systems</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>