<?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 Jhonatan Ríchard Raphael on Medium]]></title>
        <description><![CDATA[Stories by Jhonatan Ríchard Raphael on Medium]]></description>
        <link>https://medium.com/@jraphael?source=rss-ff102d9f1d39------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*i6KX-rLmXVtBUDKKRZy0bQ.jpeg</url>
            <title>Stories by Jhonatan Ríchard Raphael on Medium</title>
            <link>https://medium.com/@jraphael?source=rss-ff102d9f1d39------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 07:20:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@jraphael/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[Architectures for Distributed Systems]]></title>
            <link>https://jraphael.medium.com/architectures-for-distributed-systems-2ba4d191ffff?source=rss-ff102d9f1d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/2ba4d191ffff</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Jhonatan Ríchard Raphael]]></dc:creator>
            <pubDate>Fri, 04 Dec 2020 14:47:47 GMT</pubDate>
            <atom:updated>2020-12-04T15:49:08.067Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello guys, how are you? Today I will write about architectures for Distributed Systems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XSVOS1zcZmW6iZEHdDZS9w.jpeg" /></figure><p>An important distinction who we need to do about <strong>concepts</strong> is what are <strong>system architecture</strong> and <strong>software architecture</strong>.</p><p>A system architecture is about how the components of a distributed system are placed across multiple machines. It <strong>focuses on the entire system</strong>. An example would be a e-commerce system containing a web front-end, a service layer, and a database.</p><p>About the software architecture, it tells us about the logical organization of software components, that is, how they interact between them, your structures, how they can be independent of them, and so on. <strong>Focuses about components</strong>. It is at a lower level than the system architecture. Software architecture is a type of system architecture. Example: A component of a e-commerce system is the web front end.</p><h4>System architectures</h4><p>We have two main systems architectures that we use today: <strong>client-server</strong> and <strong>Peer-to-peer</strong> (P2P).</p><p>The client-server architecture has two main components: the client and the server. The server is where all the necessary processing takes place, while at the client it is where the user can access the services provided by the server. Usually, there is only one server that is on the remote side, but for security we use multiple servers, which will use load balancing techniques (I will write about it in another article). This architecture has advantages such as being easier to build and maintain, in addition to better security. On the other hand, it has disadvantages such as a single point of failure and less scalability. A client-server architecture reflects the traditional way of modularizing software, which is one module invoking functions in another module. Placing different software components on different machines leads to a natural physical distribution of functions over a collection of machines.</p><p>In the Peer to Peer (P2P) architecture, a node can request a service or provide it. The main idea of this architecture is that there is no central control in the distributed system. Each node can be a client or server at a certain time, depending on its action. Each node is generally known as a peer.</p><h4>Architectural styles in Software Architecture</h4><p>Now let’s talk about the logical organization of distributed systems in software components, that is, software architecture.</p><p>A common keyword in literature when we talk about distributed architectures is <strong>architectural style</strong>. An architectural style is formulated in terms of components, it is the way in which these components are connected together and how data is exchanged between the components. <strong>Components</strong> are modular units with well-defined interfaces. In addition, they have characteristics of being replaceable and reusable. <strong>Connectors</strong> are communication links between modules that coordinate between components. Therefore, the idea behind distributed architectures is to have components presented in different ways, where the components can communicate with each other over a network. The use of different configurations of components and connectors leads us to <strong>four main architectural styles</strong> for distributed systems:</p><ul><li>Layered architecture</li><li>Objects-centered/SOA architecture</li><li>Resource-based architecture</li><li>Events-centered architecture</li></ul><p>We can have a combination of these architectural styles. I will tell you a brief idea about each of the styles, since we will cover the main topics in more detail in the next posts.</p><p><strong>Layered architectures</strong>: the idea in this architecture is simple: components are organized in a layered format where a component in a layer can to do a downcall a lower-layer component, and usually waits for an answer. Only in exceptional cases a component can to do a upcall to a higher level component.</p><p><strong>Object-based architectures</strong> and <strong>service-oriented architectures (SOAs)</strong>: This architectural style is based on an arrangement of loosely coupled objects, it is less structured. Each object corresponds to what we define as a component. The connector is an RPC (remote procedure call) or RMI (Remote method invocation). Some popular examples are Java RMI, Web Services and REST API Calls. In the case of distributed systems, the calling object does not need to be executed on the same machine as the called object. Object-based architectures are attractive because they provide a natural way to encapsulate data (called the “state” of the object) and the operations that can be performed on that data (which are called “methods” or behavior of the object) in a single entity. The interface provided by an object hides implementation details, meaning that at first we can consider an object completely independent of its environment.</p><p>Someone could say that object-based architectures form the foundation of encapsulating services in independent units. Encapsulation is the key word here: the service is seen as a separate entity, although it can make use of other services. Separating services so that they can operate independently leads to service-oriented architectures, often abbreviated as SOAs. In a service-oriented architecture, an application or distributed system is essentially built as a composition of different services.</p><p><strong>Resource-based architectures</strong>: one of the problems with service composition is that connecting multiple components can easily lead to an integration nightmare. Alternatively, someone can view a distributed system as a large set of features that can be individually managed by components. Resources can be added or removed by applications, and can also be retrieved or modified. This approach has been widely adopted on the Web and is known as REST. RESTful architecture has become popular due to its simplicity.</p><p><strong>Publish-subscribe architectures</strong>: It is an architecture in which there is a strong separation between processing and coordination. The idea is to view the system as a collection of processes operating autonomously. In this model, “coordination” deals with communication and cooperation between processes. The key feature is that the processes have no explicit reference to each other. Communication takes place describing the events that the subscriber is interested in.</p><p>Well, that’s it for today. Leave your comments, suggestions or comments below. I will be back in the next post writing about types of <strong>Communication</strong> between nodes.</p><p>See you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2ba4d191ffff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction to Distributed Systems]]></title>
            <link>https://jraphael.medium.com/an-introduction-to-distributed-systems-fa2e727c52f4?source=rss-ff102d9f1d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa2e727c52f4</guid>
            <category><![CDATA[replication]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[partitioning]]></category>
            <category><![CDATA[sharding]]></category>
            <dc:creator><![CDATA[Jhonatan Ríchard Raphael]]></dc:creator>
            <pubDate>Mon, 16 Dec 2019 05:49:03 GMT</pubDate>
            <atom:updated>2020-01-02T23:58:41.537Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kcrrW9lsA1E5j99YkVJEZA.jpeg" /></figure><p>Hi! Today I will start a series of posts about an important branch in Computer Science: <strong>Distributed Systems</strong> and related topics. But why did I decide to write about Distributed Systems? What is the relevance of this? What is the motivation?</p><p>Distributed systems has had a huge rise in recent years. Subjects like mobile apps, cloud computing, analytics, data/CPU intensive apps and Big Data have boosted the use of distributed resources on the Internet. If you simply need to develop an application that has some kind of processing or storage on some server, as well as using the Internet, you need to thinking about the challenging scenario of distributed systems.</p><p>There are several good technical reasons that have made distributed systems a very powerful option. Some examples:</p><ul><li><strong>Scalability</strong>: If your data volume, read load, or write load is too large for a single machine, you can spread the load across multiple machines.</li><li><strong>Fault tolerance/high availability</strong>: If your application needs to keep running even if a machine crashes, you can use multiple machines to gain <em>redundancy</em>.</li><li><strong>Latency</strong>: If you have users worldwide, you can have servers worldwide so that each user can be served by a nearest datacenter. This saves users from having to wait too long for packages to travel over the network.</li></ul><p>The general idea of the series will be to try to answer, directly and clearly, the following question: “<em>What is the necessary theory within Distributed Systems that every software engineer should know</em>?”, trying to apply this knowledge in our daily life. Understanding the meaning of concepts such as ACID, CAP theorem, Partitioning, Replication, eventual consistency, helps us make architectural decisions and become better software engineers. Well, let’s go!</p><h3>What is a distributed system?</h3><p>Two relatively recent inventions have helped us to connect computers: more efficient microprocessors and more powerful networks. The result is that it is now possible to build a computer system consisting of a large number of nodes (computers or software processes) on the network. These computers are geographically dispersed, forming a “distributed system”.</p><p>An interesting property is that a distributed system is viewed for users as a single system (<strong>transparent distribution</strong> principle). Implementing this collaboration between nodes is very difficult and is the <em>core</em> of distributed systems. Building a distributed system may not always be a good idea. We have many advantages as we talked about earlier but there are many challenges that can complicate the development, and in many cases it is not feasible with regard to system requirements.</p><p>A distributed system has several design goals such as <strong>easy resource sharing</strong>, <strong>transparent distribution</strong> to users and applications, being <strong>openness</strong> to other systems through integration components, but the main factor to be aware of is that the system must be <strong>scalable</strong>.</p><p>Before getting into scalability, I will first take the topic to define two very important concepts within scalability and distributed systems in general: synchronous and asynchronous communication. I will talk more about <strong>Communication</strong> of distributed systems in another post, involving topics such as RPCs and message-oriented communication.</p><h3>Synchronous communication versus asynchronous communication</h3><p>In <strong>synchronous communication</strong>, a requesting service, usually referred to as client, blocks the process until the response is sent by the server that implemented the service. Communication between two people is an example of synchronous communication. In the context of a software system, an example would be a client node only showing front-end data to the user after another server node delivers the data to the client.</p><p>In <strong>asynchronous communication</strong> there is no client blocking the process and the processing of sending a message is done without waiting for a response from the server. The sending node is released to perform other tasks, possibly before the message has been sent. For example, when you send an email. You open and reply to the email anytime after delivery.</p><p><strong>Multithreading</strong> plays a major role in asynchronous communication. In addition to allowing you to perform independent tasks in parallel, threads allow you not to lock the application while a task result is expected. Therefore, threads play an important role in both undistributed and distributed environments.</p><h3>Scalability</h3><p>Getting back to scalability, a very common term for us developers but often misunderstood. The scalability of a system can be measured across at least three different dimensions:</p><ul><li><strong>Size Scalability</strong>: a system being scalable relative to its size means we can add more users and resources to the system without notable loss of performance. This often happens in centralized services, which can affect a distributed system. Example: Let’s assume a service is deployed on a single node. In this case, there are three possible causes that can make a bottleneck: <strong>computational capacity</strong>, limited by CPUs. <strong>Storage capacity</strong>, including I/O rate and a <strong>network</strong> between the users and a centralized service;</li><li><strong>Geographic scalability</strong>: in a geographically scalable system, users and resources may be far apart physically, but communication delay is hardly seen. On systems that need a lot of synchronous communication, this can be a big problem because this scenario works well on LANs, where communication is faster, but would fail on WANs. Example: A communication pattern that has many interactions with database transactions. (I will talk about transactions in another post). Another problem is that communication in wide area networks is less reliable than in local area networks. Also, we need to deal with limited bandwidth. The effect is that solutions developed for LANs cannot easily be ported to WANs. A clear example of this would be a video streaming server;</li><li><strong>Administrative Scalability</strong>: An administratively scalable system is one that can be easily managed even if it expands many independent administrative organizations. A recurring problem is the needing to address conflicting policies regarding use of resources, management, and security.</li></ul><h3>Techniques for scaling a distributed system</h3><p>In most cases scalability issues in distributed systems appear as performance issues caused by <em>limited capacity of servers </em>and<em> networks</em>. There are two ways to try to work around this problem:</p><ol><li>If you need to scale to higher loads, the simplest approach is to increase hardware capabilities (examples: Increase memory, CPU, or exchange network modules), which is a solution named <strong>Scaling Up</strong> or <strong>Vertical Scaling</strong>. In this kind of shared-memory architecture, all hardware components can be treated as a single machine. The problem with the approach of shared memory is that the cost grows faster than a linear cost: a machine with double CPU, double RAM, and double disk capacity is typically more expensive than twice its original price. Also, due to communication bottlenecks, a machine with twice the computational power cannot handle twice the load. A disadvantage of shared memory architecture is that it is limited to a single geographic location, which can increase the latency of your application. Another approach is the “shared-disk architecture”, which uses many machines with independent CPUs and memory, but stores data on an array of disks that is shared between machines, which are connected through a fast network. The problem with this architecture is contention and the overhead of scalability limit.</li><li>When we talk about <strong>Scaling Out</strong> or <strong>Horizontal Scaling</strong> (shared-nothing architectures), we add additional infrastructure to our system (deploying more machines, virtual machine or containers). In contrast to memory-shared architectures, shared-nothing architectures have gained a lot of popularity. In this approach, each machine that runs the distributed system software is called a node. Each node uses its CPU, RAM, and disks independently. Any coordination between nodes is performed at the software level using a conventional network. In this case, there are basically 3 techniques we can apply: <strong>hiding communication problems</strong><em>, </em><strong>partitioning </strong>and<em> </em><strong>replication</strong>. I will give a short introduction to each of these techniques now but I will write another post with more details of each.</li></ol><p>a) <strong>Hiding communication latencies</strong>: applies in case of geographic scalability. The basic idea is to try to wait as little as possible for responses from remote service requests and do some useful work in the meantime. This essentially means building the application so that it uses asynchronous communication. When the response is delivered, the application is stopped and a special handler is called to complete the previous request. However, using asynchronous communication is not always possible due to application requirements and our goal is to maximize it to hide latencies and possible bottlenecks of communication. If system requirements do not allow the use of asynchronous communication, it is recommended that you decrease the overall communication of application, for example by moving some of the computation that runs on the server to the client.</p><p>b) <strong>Partitioning and distributing</strong> (also known as <strong>Sharding</strong>): This is another important scaling technique, which involves taking a component, dividing it into smaller parts, and then distributing it across the system nodes. Good examples are the Internet Domain Name (DNS) and the World Wide Web.</p><p>c) <strong>Replication</strong>: Given the fact that scalability issues often arise in the form of performance degradation, it is generally a good idea to replicate components across a distributed system. Replication not only increases higher <em>availability</em> by providing <em>redundancy</em>, but also helps to balance the load between components leading to <em>better performance</em>. Also, on widely geographically dispersed systems, having a close copy can <em>hide communication latency</em> issues mentioned earlier.</p><p><strong>Caching</strong> is a special form of replication, although distinguishing between the two is hard. Just like replication, caching is making a copy of a resource, usually in the proximity of the client accessing the resource. However, in contrast to replication, caching is a decision made by the client of a resource and not by the owner of a resource.</p><p>There is a serious problem with caching and replication that can affect scalability. Because we now have multiple copies of a resource, modifying a copy can make that copy different from others. Consequently, caching and replication leads us to <strong>consistency</strong> problems, which we’ll cover in another post. Replication often requires some kind of global <em>synchronization</em> mechanism to keep nodes consistent. Unfortunately, such mechanisms are extremely difficult or even impossible to implement in a scalable manner, because network latencies are a natural lower bound. Consequently, scaling by replication may introduce other related non-scalable solutions.</p><p>Practice shows us that combining Partitioning, Replication, and Caching techniques with different forms of consistency often leads us to acceptable solutions for size scalability and geographic scalability. Finally, administrative scalability seems to be the most difficult problem because we need to deal with non-technical issues such as organizational policies and human collaboration.</p><p>Well, that’s it for today. Leave your comments, suggestions or comments below. I will be back in the next post writing about <strong>Architectures of distributed systems</strong> and types of <strong>Communication</strong> between nodes.</p><p>See you there!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa2e727c52f4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learn “Reconciliation” and develop faster React apps]]></title>
            <link>https://jraphael.medium.com/learn-reconciliation-and-develop-faster-react-apps-a355cdbc8124?source=rss-ff102d9f1d39------2</link>
            <guid isPermaLink="false">https://medium.com/p/a355cdbc8124</guid>
            <category><![CDATA[reconciliation]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[mobile]]></category>
            <dc:creator><![CDATA[Jhonatan Ríchard Raphael]]></dc:creator>
            <pubDate>Sun, 27 Jan 2019 14:54:24 GMT</pubDate>
            <atom:updated>2019-02-07T16:20:39.002Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0B1--z9NZUgUlzQaOTd-_g.png" /></figure><p>If you are using React, you should understand how the Reconciliation process works. Why? This algorithm is the great trick behind React’s performance and understanding how it works helps in the decision making process for creating better performance apps.</p><p>The <a href="https://reactjs.org/docs/reconciliation.html">React documentation</a> explains how the algorithm works but the idea here is to deepen it a bit more.</p><h3>The problem</h3><p>An advantage of React over iOS and Android SDK&#39;s is that the developer has less effort in implementing screen updates. But for this to be possible, the React API needs to solve a complex problem of <strong>reconciliation</strong> of components.</p><p>Every time that your application updates a class component through the <a href="https://reactjs.org/docs/react-component.html#render">render()</a> method, invoked after updating the <a href="https://reactjs.org/docs/react-component.html#state">state</a> or <a href="https://reactjs.org/docs/react-component.html#props">props</a> attributes, it is necessary to reorganize a data structure with those components, an object named <strong>Virtual DOM</strong>. This data structure is a <strong>tree</strong> that stores all objects of your application in memory. This tree aims to maintain the states of the components, and it is the object returned by the algorithm of reconciliation.</p><p>To keep the Virtual DOM consistent, we have a common problem known in Computer Science, called <a href="https://grfia.dlsi.ua.es/ml/algorithms/references/editsurvey_bille.pdf">Tree Edit Distance</a>. In this problem we have to calculate the minimum distance between two trees, transforming one tree into another tree. The state of the art of this problem is composed of dynamic programming algorithms that aims to reduce the number of subproblems in the trees. The optimal algorithm, known so far, has time complexity O(n³) in the <strong>worst case</strong>, where <em>n</em> is the number of elements in the tree. That way, we have a critical problem, since the main component of your screen may have thousands of child components, which would greatly affect the performance of your app.</p><p>To overcome this problem, the React reconciliation algorithm uses a heuristic approach, with time complexity θ(n) in the <strong>average case</strong>, trying to minimize the number of nodes to be updated in the tree. This avoids the worst case in the vast majority of cases. Let’s understand how this works.</p><h3>Behavior of the algorithm</h3><p>The algorithm follows <a href="https://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first search</a> strategy, which can be understood recursively or through a queue. The two trees (or sub-trees) are analysed trying to take advantage of the following two scenarios:</p><ol><li>If the root nodes are of <strong>different types</strong>, then it is likely that we will have very different sub-trees, so we do not need to analise them completely. In this case, the old tree is destroyed and a new tree is created with the new root, invoking the <a href="https://reactjs.org/docs/react-component.html#render">render()</a> method for all children nodes again. The old node is destroyed, invoking <a href="https://reactjs.org/docs/react-component.html#componentwillunmount">componentWillUnmount()</a>, and the new node will be mounted, invoking <a href="https://reactjs.org/docs/react-component.html">componentWillMount()</a> and <a href="https://reactjs.org/docs/react-component.html#componentdidmount">componentDidMount()</a>. The entire state of the old tree nodes is lost and it is important for the developer to know that.</li><li>If the root nodes are of the <strong>same type</strong>, the algorithm checks the list of children of the compared nodes and generates a mutation whenever it identifies any difference. The parent node is preserved in the tree, maintaining its state. The algorithm tries to be efficient updating only those attributes that need to be updated, regardless of the ordering. The component instance to be updated receives the <a href="https://reactjs.org/docs/react-component.html">componentWillReceiveProps()</a> and <a href="https://reactjs.org/docs/react-component.html">componentWillUpdate()</a> methods.</li></ol><p>This process continues recursively to the next children nodes. The worst case of the algorithm is when none of the above cases occurs.</p><h3>Tips for developers to improve the performance</h3><h4>Generate stability for your components with the &quot;key&quot; attribute</h4><p>In scenario 2 explained above, a naive algorithm could be very inefficient to compare the two arrays of elements, θ(n²) in the worst case. The use of keys makes it possible to do this check (insertion, deletion, substitution and moves) in <strong>linear time</strong>, regardless of the order of the elements compared, improving the time average case of the reconciliation algorithm. Here is an example code:</p><pre>&lt;ul&gt;<br> &lt;li key=”2018&quot;&gt;Uberlândia&lt;/li&gt;<br> &lt;li key=”2017&quot;&gt;São Paulo&lt;/li&gt;<br>&lt;/ul&gt;</pre><pre>&lt;ul&gt;<br> &lt;li key=”2019&quot;&gt;Brasília&lt;/li&gt;<br> &lt;li key=”2018&quot;&gt;Uberlândia&lt;/li&gt;<br> &lt;li key=”2017&quot;&gt;São Paulo&lt;/li&gt;<br>&lt;/ul&gt;</pre><p>The tags &lt;ul&gt; are the compared type and the lists of &lt;li&gt; are the children. With keys, the algorithm identifies that element 2019 (Brasília) is a new element, eliminating mutations in the other children elements 2018 and 2017.</p><p>When defining the keys it is important to ensure that they are <strong>unique</strong> and <strong>stable</strong>. Keys with some kind of randomness will create many undesired nodes in the tree, which can cause degradation of performance and loss of state of children components. In case the keys are not unique, the algorithm gets lost and unexpected behavior may occur in the updates.</p><p>When your data model does not provide a good identifier for your component, you can create a key using the other attributes as parameters in a <a href="https://en.wikipedia.org/wiki/Hash_function">hash</a> function. Another option is to use the index of the item in the array as its key, ensuring that those items will not be reordered.</p><h4>Avoid Reconciliation Scenario 1 for similar outputs</h4><p>If you, as a developer, realize that you are updating your components so that the roots are different and their sub-trees looks similar, we fall into scenario 1 and you need to work around this so you do not degrade the performance of your app. Replace your root components for the same type.</p><h3>Conclusion</h3><p>Developing apps in React Native can be quite nice indeed. Having said that, we understand that it is very important for the developer to know how the core works, so we can take full advantage of its performance features.</p><p>Please, leave your comments, doubts and feedbacks down below. Thank you!</p><p><a href="https://medium.com/u/ff102d9f1d39">Jhonatan Ríchard Raphael</a> is a Software Engineer working at <a href="https://www.ibm.com/services/ibmix/">IBM iX</a>. We are transforming industries by design!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a355cdbc8124" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>