<?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 David on Medium]]></title>
        <description><![CDATA[Stories by David on Medium]]></description>
        <link>https://medium.com/@SoulBits?source=rss-cb8ebffaf995------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*lR_Y2QMjoQCDivqU.jpg</url>
            <title>Stories by David on Medium</title>
            <link>https://medium.com/@SoulBits?source=rss-cb8ebffaf995------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 23:16:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@SoulBits/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[Visually Understanding Worker Pool]]></title>
            <link>https://medium.com/coinmonks/visually-understanding-worker-pool-48a83b7fc1f5?source=rss-cb8ebffaf995------2</link>
            <guid isPermaLink="false">https://medium.com/p/48a83b7fc1f5</guid>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[David]]></dc:creator>
            <pubDate>Thu, 19 Jul 2018 22:53:06 GMT</pubDate>
            <atom:updated>2022-06-26T18:36:18.431Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/793/1*wJj8RpGPCkiWHot2R8m0KA.png" /><figcaption>Example diagram of a worker pool process in Go using goRoutines</figcaption></figure><p>The problem we need to focus on is creating a more <strong>visual</strong> approach to understand patterns and some other <strong>solution architectures</strong> that could create a blackbox situation in your internal team if they are not understood correctly.</p><p>Often, we are tempted to “copy and paste” code and don’t even realize how things work in the underlying layers. Today, we are going to review the famous (yet <strong>underrated</strong>) Worker Pool (aka Thread Pool). In <strong><em>Go, </em></strong>this is commonly approached using <a href="https://tour.golang.org/concurrency/3">buffered channels</a> as the main queues and communication channels between goRoutines. Understanding <a href="https://tour.golang.org/concurrency/2">channels</a> before continuing with this post is more than advised for a clearer comprehension.</p><h4>Understanding the Diagram</h4><p>We started this post showing a high level diagram of a worker pool implementation in <strong><em>Go</em></strong>. It resumes the main operations that need to happen in any worker pool implementation:</p><ul><li>“Allocate” resources to be processed</li><li>“Work” (or process) those resources</li><li>and “Collect” the results for further post-processing</li></ul><p>These operations can be accomplished in different ways, even a single script with iterative lines, but today we are going to use a concurrent and parallel design in <strong><em>Go </em></strong>to maximize the hardware resources available, obtain results as fast as possible and continue the tendency towards <a href="https://en.wikipedia.org/wiki/Microservices">microservice</a> architecture.</p><p>Let’s see at each component in a more detailed “zoomed-in” fashion:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*92DJtQvn97l9laNSSgySIw.png" /></figure><p>The <strong>main GoRoutine is the normal program execution</strong>, for this case our program does little in specific since we are focusing in worker pool, the only specific task to perform is spawning and controlling other GoRoutines related to the proper execution of the Worker Pool</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5e55411b162bfd0337a7936e730b72aa/href">https://medium.com/media/5e55411b162bfd0337a7936e730b72aa/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/118/1*sRILIAI_vdePF-I5SeoWHA.png" /><figcaption>Boolean Channel “Done”</figcaption></figure><p>The <a href="https://tour.golang.org/concurrency/2">channel</a> “Done” ( done chan bool) is used as the main program control which indicates that all tasks has been performed and all goRoutines completed. Different from the “main loop” design, the main GoRoutine waits for a signal to be sent via this channel to stop and end the program. Why we use a channel to control the program execution and wait for all goRoutines is easy to respond: <strong>simplicity</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af6f15149a71cc208cb349b4d513972f/href">https://medium.com/media/af6f15149a71cc208cb349b4d513972f/href</a></iframe><p>In the previous example, our program waits to continue the execution until the channel variable “done” ( &lt;-m.done) receives a value. This makes the code smaller and easy to read.</p><h4>Allocating Resources</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/545/1*-ceu-kkvm8ScoZ4qSUA6Aw.png" /><figcaption>“Allocate” goRoutine</figcaption></figure><p>“Allocate” goRoutine is a sub routine that spawns from the main goRoutine, its purpose is to <strong>allocate resources</strong> that are going to be used by the worker pool. It has a main loop with a limited lifetime: until all the resources has been allocated. To better understand this, lets take a look at the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AkEMYppxgaHEvExDQgRGbw.png" /><figcaption>“Allocate” goRoutine tasks</figcaption></figure><p>“<em>As long as there are resources to Allocate, the goRoutine is going to continue its operation</em>” is the expression that better describes the previous diagram. The allocation execution receives in an array of unknown size of resources and iterates over the array, converts it to a structure “Job” that can be later on processed by another goRountine. The resources being converted to “Job” is sent to a buffered channel “Jobs” which has limited size/dimension. You might have noticed that in the example, the array of Resources is bigger than the elements that can be buffered/sent in the channel, and this is by design intended as <strong>it controls the number of parallel Jobs that can be performed simultaneously</strong>. That’s it, if the “Jobs” channel is full the <strong>iteration over resources will halt</strong> until it can allocate Jobs in the Jobs channel again.</p><p>Why are we converting Resources to Channel Jobs obeys the design principle of <a href="https://en.wikipedia.org/wiki/Separation_of_concerns"><strong>Separation of Concerns</strong></a><strong>. </strong>Resources being sent to the Jobs channel are going to be picked up by another goRoutine for later processing, limiting the concern of the allocation to only receiving, converting and allocate. The following code represents the discussed diagram:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1af281c327a35278ee6a139c0c77d60c/href">https://medium.com/media/1af281c327a35278ee6a139c0c77d60c/href</a></iframe><h4>Processing the Jobs Channel (Jobs to be Done)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*RnZEbhtvkqEPHl4k7-yBkQ.png" /></figure><p>“Worker Pool” goRoutine existence is defined by the “Jobs” Channel: As long as there are jobs that need to be worked on and processed, continue doing so. Continuing with the <a href="https://en.wikipedia.org/wiki/Separation_of_concerns"><strong>Separation of Concerns</strong></a><strong> </strong>this goRoutine purpose is the actual processing of Jobs, and as most-things-go, it works concurrent and in parallel. This is the <strong>most critical section</strong> of our discussion as is covers the <strong>creation and work assignment of the worker pool</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fSAs6yzp2CZrN4rY0Qp6cw.png" /><figcaption>Worker Pool using Sync.WaitGroup to control spawning new GoRoutines</figcaption></figure><p>In this case, the worker pool goRoutine spawns new “work” (or “worker”) goRoutines, how many to <a href="https://gobyexample.com/goroutines">spawn</a> is defined by configuration or injected into our solution, for now lets define “3” as the number of workers in the pool. One <strong>key factor</strong> of any worker pool (or thread pool) is to control the size of the pool, if you don’t do so, chances are that hardware resources are going to be exhausted or even your program deadlocked.</p><p>We are going to simplify our solution by using <a href="https://nanxiao.me/en/use-sync-waitgroup-in-golang/">Sync.WaitGroup</a> which basically servers as structure that we can ask anytime to see if all the goRoutines have completed. Similar to our “Done” Channel, the <a href="https://golang.org/pkg/sync/#WaitGroup">WaitGroup</a> package exposes a <a href="https://golang.org/pkg/sync/#Cond.Wait">Wait</a> method that will halt the execution until a value is received. The code looks similar to:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbe8131cc18af501e02886102af10f85/href">https://medium.com/media/fbe8131cc18af501e02886102af10f85/href</a></iframe><p>As you might have noticed it, the synchronisation is just an atomic counter that we increment ( Add) and then we decrement ( Done) inside each sub-goRoutine. Then the workerPool halts execution until wg.Wait() condition is satisfied.</p><p>Now let’s look into the actual execution of each “work” (or worker) to better understand all the synchronisation and actual processing of the Jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o6H0OifPErk1Hxzv4I1Esg.png" /><figcaption>“Work” goRoutine process</figcaption></figure><p>In the WokerPool goRoutine we saw how we <a href="https://gobyexample.com/goroutines">spawn</a> new “work” goRoutines inside the for loop by calling go m.work which will create the new goRoutine(s).</p><p>Inside this new goRoutine, is the actual<strong> processing of the Jobs and assigning results</strong>, for this, each new “work” goRoutine will perform a for range jobs loop over the channel “Jobs”. The effect this has is that each work routine will grab a <strong>unique</strong> Job due to the implementation of Channels in Go which uses locks and makes sure only one item in the channel can be picked up by a goRoutine, this also defines the <strong>lifetime</strong> of a “work” goRoutine: <strong>as long as there’s work to do in the Jobs channel, continue iterating</strong>. This technique exposes a better reading and understanding of the code, which hides all the machinery of locking and unlocking a shared structure between processes.</p><p>Once we pick a Job from the channel “Jobs” we process it and create a “Result” object that is then sent to a “Results” channel. This is a continuation of our adopted <a href="https://en.wikipedia.org/wiki/Separation_of_concerns"><strong>Separation of Concerns</strong></a><strong> </strong>design, the lifetime of a “work” goRoutine is defined by the amount of time it takes to process a “Job” and the result sent to the “Results” channel, it will iterate again over the “Jobs” channel if its not closed yet.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ef1070ab6c8907710d8ae03ceaca9985/href">https://medium.com/media/ef1070ab6c8907710d8ae03ceaca9985/href</a></iframe><p>The previous code represents this chapter, as you can see, the variable wg ( sync.WaitGroup)is passed as reference to the method so when we finish processing all the &quot;Jobs” we can call wg.Done() letting the parent goRoutine (workerPool) know that this specific goRoutine has finished.</p><p><strong><em>Bonus Content:</em></strong> the actual processing of the Job does not happen anywhere in the code we have published so far, this is because we are using<a href="https://en.wikipedia.org/wiki/Dependency_injection"> Dependency Injection</a> specifically by using the function signature ProcessorFunc as an argument to the worker pool and then to the work goRoutine, this isolates the actual implementation of the worker pool and processing the work is accomplished in another layer, keeping it simple to reuse.</p><h4>Gathering the Results</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*ZNZOa8-wu_TVd-NrC7MKbQ.png" /><figcaption>“Collect” goRoutine</figcaption></figure><p>So what we should do once results are being sent to the “Results” Channels? The answer is simple: <strong>collect, process it and delegate the result</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AjACyrNcUPelxltqj6Qlcg.png" /></figure><p>Our buffered channel “Results” keeps all the results from all the workers, so we have a different approach to process this “queue” (in this case we just iterate over them). The important part about this implementation is <strong>understanding that processing a Job has a different concern than processing its results</strong>. One can take different actions depending on the outcome.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d71ec305d4ec9106b23a91e4226ee1d0/href">https://medium.com/media/d71ec305d4ec9106b23a91e4226ee1d0/href</a></iframe><p>From the previous code is important to understand and correlate with the diagram a few factors:</p><ul><li><a href="https://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a> is used again to inject the result into the “post-processor”, this creates a <strong>delegation</strong> of the result outside the pool context where the injected function can take different actions.<br>The signature for this Type is similar to: <br>type ResultProcessorFunc func(result Result) error</li><li>We are just iterating over the channel, <strong>this defines the lifetime of the collect routine</strong>. We can swap this approach and create another pool of workers to speed up the post-processing of results, but by design, this should not be necessary since processing a “Job” in the “work” goRoutines should in theory take more time that post-processing the result. If the later is not satisfied in your design it means you might have many business logic rules in the result that might be worth looking into and be moved to the “Job” processing.</li><li>The m.done &lt;- true at the end signals the “Done” channel letting the main goRoutine know that the worker pool has finished.</li></ul><h4>What’s Next?</h4><p>At this point we have diagramed, understood and implemented a full concurrent, parallel and abstract worker pool in <strong>Go</strong>. The practice of creating <strong>visual representations and/or diagrams of our solutions to problems</strong> has been heavily appreciated since the beginning of the information era. It helps you abstract, find patterns and opportunities to improve your solutions and hopefully, create fertile soil for better documentations.</p><p>Feel free to grab the entire code and some examples here:</p><p><a href="https://github.com/dmora/workerpool">dmora/workerpool</a></p><blockquote>Join Coinmonks<a href="https://t.me/coincodecap"> Telegram Channel</a> and<a href="https://www.youtube.com/c/coinmonks/videos"> Youtube Channel</a> get daily <a href="http://coincodecap.com/">Crypto News</a></blockquote><h4>Also, Read</h4><ul><li><a href="https://medium.com/coinmonks/top-10-crypto-copy-trading-platforms-for-beginners-d0c37c7d698c">Copy Trading</a> | <a href="https://medium.com/coinmonks/crypto-tax-software-ed4b4810e338">Crypto Tax Software</a></li><li><a href="https://coincodecap.com/grid-trading">Grid Trading</a> | <a href="https://medium.com/coinmonks/the-best-cryptocurrency-hardware-wallets-of-2020-e28b1c124069">Crypto Hardware Wallet</a></li><li><a href="http://Top 4 Telegram Channels for Crypto Traders">Crypto Telegram Signals</a> | <a href="https://medium.com/coinmonks/crypto-trading-bot-c2ffce8acb2a">Crypto Trading Bot</a></li><li><a href="https://medium.com/coinmonks/crypto-exchange-dd2f9d6f3769">Best Crypto Exchange</a> | <a href="https://medium.com/coinmonks/bitcoin-exchange-in-india-7f1fe79715c9">Best Crypto Exchange in India</a></li><li><a href="https://coincodecap.com/binance-vs-bitstamp">Binance vs Bitstamp</a> |<a href="https://coincodecap.com/bitpanda-coinbase-coinsbit"> Bitpanda vs Coinbase vs Coinsbit</a></li><li><a href="https://coincodecap.com/buy-ripple-india">How to buy Ripple (XRP)</a> |<a href="https://coincodecap.com/crypto-exchange-africa"> Best Crypto Exchanges in Africa</a></li><li><a href="https://coincodecap.com/crypto-exchange-africa">Best Crypto Exchanges in Africa</a> |<a href="https://coincodecap.com/hoo-exchange-review"> Hoo Exchange Review</a></li><li><a href="https://coincodecap.com/etoro-robinhood">eToro vs Robinhood</a> |<a href="https://coincodecap.com/bybit-bityard-moonxbt"> MoonXBT vs Bybit vs Bityard</a></li><li><a href="https://medium.com/coinmonks/best-crypto-apis-for-developers-5efe3a597a9f">Best Crypto APIs</a> for Developers</li><li>Best <a href="https://medium.com/coinmonks/top-5-crypto-lending-platforms-in-2020-that-you-need-to-know-a1b675cec3fa">Crypto Lending Platform</a></li><li><a href="https://medium.com/coinmonks/free-crypto-signals-48b25e61a8da">Free Crypto Signals</a> | <a href="https://medium.com/coinmonks/crypto-trading-bot-c2ffce8acb2a">Crypto Trading Bots</a></li><li>An ultimate guide to <a href="https://medium.com/coinmonks/leveraged-token-3f5257808b22">Leveraged Token</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=48a83b7fc1f5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/visually-understanding-worker-pool-48a83b7fc1f5">Visually Understanding Worker Pool</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Distributed Environments and Data Storages]]></title>
            <link>https://medium.com/coinmonks/distributed-environments-and-data-storages-7926773941bf?source=rss-cb8ebffaf995------2</link>
            <guid isPermaLink="false">https://medium.com/p/7926773941bf</guid>
            <category><![CDATA[grpc]]></category>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[David]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 21:21:41 GMT</pubDate>
            <atom:updated>2018-08-06T07:15:33.968Z</atom:updated>
            <content:encoded><![CDATA[<h4>A subtle guide on how to avoid the race condition (and eventually, concurrency) nightmare</h4><h4>Before digging into the topic</h4><p>In distributed environments there are quite a few considerations that one has to have clear before starting any enterprise. These considerations have to be set from the ground before starting because otherwise, as many other endeavours, the infamous technical debt will take a big hit at your team’s performance and never ending list of bugs when the product or feature releases, affecting your product’s health.</p><p>One of the most overlooked components when things get this messy is the data storage and race conditions (and most of the time in conjunction with concurrency issues, it is kind of a combo). This is often not present in monolithic applications since their concern is centralized, but they offer another wide set of problems that we will not discuss today.</p><p>The natural design of distributed environments makes a really healthy soil for problems like these to flourish, and the fact is, that there is no holy grail that can save you from this, you need to design and expect failure as part of your architecture. Some teams struggle when components are built on top of other architecture and solution inheriting the underlying problem, thus suffering symptoms which tend to confuse with other kind of situations.</p><p>It is also important to remember that distributed environments not only apply to those systems talking between each others in B2B applications, but also customer facing applications like JS web applications, IoTs and mobile applications. They all handle objects in a state (or reactive) nature that depends on a underlying storage.</p><h4>The Problem</h4><p>Consider the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*wAPgMOZfi8gkFzq93Fmhfw.jpeg" /></figure><p>The following events happened:</p><ol><li>An object is stored in a database and then requested by a service (A)</li><li>microseconds (or any relevant unit of time) later another replica of the object is requested by another service (B)</li><li>Service A makes a change in the object and it is saved in the datastore</li><li>Service B makes a change in the object and it is saved in the datastore microseconds later.</li><li>At this point, changes made by Service A are lost</li></ol><blockquote>So .. what happened? Data has been overwritten</blockquote><p>In distributed systems an object belongs to a component/system (owner) and for other components to access it they need to ask the owner for a replica of the object. For instance, there is a microservice that manage user profiles, so anytime a component wants to interact with a user profile it asks this microservice for access. Any modification to this replica might be saved to the storage by sending back the object to the microservice owner. Now if you multiply this by the amount of operations and components interchanging and interacting over the data, the previous example in the diagram will most likely happen and is something difficult to spot, but happens.</p><p>This situation is indifferent of the transmission protocol, it could be a simple HTTP Form, JSON-REST, WSDL web service, web-socket, grpc … you name it, at the end the problem belongs to the data layer and business logic, not the transmission layer.</p><p>This is a trade off from having each component or microservice access the underlying database directly via SQL (or any other language), just think about adding one attribute to a table, you will have to go and modify all the components and the business rules have to be updated as well. The best way to look at this is like how a monolithic application is built, you probably have a component shared in a library that does exactly the same, so at the end, this also applies to monolithic applications at some sort.</p><h4>The Solution</h4><p>First we need to simplify the problem, or like a few would actually think: find the real problem and ask yourself what do you actually need and if you need to. Let’s review some common approaches first and the talk to the underlying problem:</p><p>A.) Paxos and any other consensus algorithms are off the table since they are more likely help data synchronization between data storage replicas (think datacenters). Which is not the problem we are discussing.</p><p>B.) You might be tempted to try Google’s probabilistic failure-aware distributed system, but do you really need it? If your SaaS main existence is based on fixing this problem, sure, otherwise it might be an overkilling approach.</p><p>C.) Keep a “last updated” field (or more expensive, computed hash attribute representation of the object) that you can check at the object’s owner to see if the object has changed before making any other modifications? This would most likely work, making sure all other components can handle the error (as said in the beginning: design and expect failure). This is done on reactive datastores which concern only to a single user in a WEBAPP or mobile, but for B2B or system to system communications is not that simple and might as well be overkilling and a performance degradation solution.</p><p>D.) Have the underlying storage and owner component support updating only changed attributes? Yes, this would work if the consumers (or services updating the replica object) only send the fields that have changed (trust). Using this approach and our first example with the diagram, this would work like a “merge” operation. But what if both are changing the same attribute? Or they depended on an attribute that change over time to make a decision?</p><p>E.) Databases already solve this problem by having transactions, row level locking, ACID components and many other features, you might ask yourself at this point, but … are you going to have all your distributed systems talk to the database directly to access objects/models? It surely works but the level of complexity that you are creating to maintain the solution is worst down the road.</p><p>F.) Have a reactive layer that will notify everyone that the storage has changed? Sure it works, and is, <strong>maybe</strong>, the best technical and fancier solution. But can your product asume how expensive it is and how complicated is to scale it? Think of a google document, just imagine all the infrastructure behind it sustaining those sockets and the pub/sub component behind it to make sure things go smoothly and realtime, is basically the same without applying business rules.</p><p>At his point we are running out of ideas, maybe the solution is between solution C.) and D.)and F.) but, are we 100% sure the problem will disappear? And the answer is <strong><em>no </em></strong>and this is why:</p><blockquote>The problem is not serial or concurrent access to data, is who is (and how) making decisions over the data and dictating is final state.</blockquote><h4>How to overcome this problem (the subtle guide)</h4><p>Make sure each component, system or service not only owns the object but the logic and business logic attached to it. If you are modifying an attribute of an object in different components you are creating a swarm-like communication issues. Using the same diagram:</p><ul><li>If Service A instead of sending the entire representation of the object’s clone to the owner service could send the value to be modified instead, the owner service can make a better decision.</li><li>If all services report changes to the owner service, the owner service can handle the situation in a stateless-like fashion.</li><li>This will extend the wrongly used nature of CRUD for API’s and other kind of interactions, as an operation becomes more than “updating”, instead, it will be a notification of something that needs to be triggered in underlying layers reacting to another rule or signal.</li></ul><p>Do not overcomplicate things, if the logic is well encapsulated and the process is simple you are by design creating a inexpensive fast processing component, which, of course, will reduce the chances of problems like this to happen.</p><ul><li>All data operations need to happen at the lowest layer, meaning this that if you can encapsulate a process in a stored procedure is going to be better than trying to solve it in other layers more oriented to solve other kind of issues.</li><li>If you dislike stored procedures or they are not available for you, the next layer who defines the object is the one that owns it and can make better decisiones that any other component.</li><li>Concurrent and Race Conditions are intrinsically connected and related with time, so the less time is spent in an operation, the better. If you have a really long process with IO or external API calls, and this process modifies an object at the end you are most likely going to experience the problem.</li><li>If the process (or method) you are creating is changing data and there’s no transactional support, you might probably want to revisit your design and approach since the chances of creating corrupted data are high … really high.</li></ul><p>At the end, moving the real concern to the owner of the service will offer a better and clearer communication that is understandable by all the components and follows the separation of concerns practice. In a world of “Object Oriented Programming 2.0” solution architectures are starting to have problems already solved in the past by trying to make code more understandable and elegant (which is fine) but overkilling at the end.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7926773941bf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/distributed-environments-and-data-storages-7926773941bf">Distributed Environments and Data Storages</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>