<?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 Mariia Romaniuk on Medium]]></title>
        <description><![CDATA[Stories by Mariia Romaniuk on Medium]]></description>
        <link>https://medium.com/@m.romaniiuk?source=rss-3293b4c743f1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kTb6SylLtgnjJB09imVMQw.jpeg</url>
            <title>Stories by Mariia Romaniuk on Medium</title>
            <link>https://medium.com/@m.romaniiuk?source=rss-3293b4c743f1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:05:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@m.romaniiuk/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[The Future is Hybrid]]></title>
            <link>https://medium.com/@m.romaniiuk/the-future-is-hybrid-424ba8dda47?source=rss-3293b4c743f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/424ba8dda47</guid>
            <category><![CDATA[product-development]]></category>
            <category><![CDATA[product-design]]></category>
            <category><![CDATA[ux-engineering]]></category>
            <category><![CDATA[ux-design]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Mariia Romaniuk]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 03:30:03 GMT</pubDate>
            <atom:updated>2023-07-28T00:31:09.041Z</atom:updated>
            <content:encoded><![CDATA[<h3>How design and engineering are merging into new forms</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H_TJfmUeEyZuR4BXSXZs6g.png" /></figure><p>I’ve been thinking about this quite a lot lately — the evolution of design and engineering and their symbiotic relationship. Historically, these two disciplines were viewed as distinct fields, with design focusing on visual aesthetics and user experience and engineering on the functional aspects of a product. However, they are becoming more intertwined.</p><p>As technology advances, engineers need to be involved in the design process at a very early stage and they also often happen to have a final say in product design decisions. Design is becoming increasingly technical (look at the Figma Config’23 presentation of variables, conditionals, advanced prototyping, Dev Mode, etc.) and requires a deeper understanding of technical concepts and tools. On the other hand, designers are shifting away from creative work increasingly engaging in roles traditionally performed by business analysts and product managers. This transition likely stems from the expanding scope of design responsibilities, which have evolved beyond mere aesthetics to encompass a thorough understanding of customer needs, business imperatives, and market trends.</p><p><em>“20% of the design team’s time is spent on UI design… 80% on everything else”, Eric Snowden, VP of Design at Adobe.</em></p><p>The overlapping area between design and development is where new cross-functional roles have started to emerge, such as Design Engineer, User Experience Engineer (UXE), Creative Technologist, User Experience (UX) Prototyper, Design System Engineer, etc. They may work on both engineering teams or design teams, or act as liaisons to fill a void between the two. We will continue to see an increasing amount of these roles surface as their significance becomes further recognized.</p><p>What does a UX engineer do, exactly? Their work includes both UX principles and engineering tasks. Here’s a breakdown of what a UX engineer can be expected to do:</p><ul><li><strong>Plan and design web pages and apps: </strong>A UX engineer uses UX principles to create digital products. This can mean using wireframes, prototypes, and design tools to create blueprints for what a website or app will look like.</li><li><strong>Program the front-end:</strong> UX engineers are unique from UX designers because they code. A UX engineer will use front-end programming languages, frameworks, and libraries to create layouts, interactive features, or execute other design ideas.</li><li><strong>Collaborate with UX and engineering teams: </strong>As a professional with both design and programming abilities, UX engineers often act as the bridge between the two teams. UX engineers work with designers, back-end engineers, and writers to develop products. They also conduct user testing, A/B testing, and other forms of research in collaboration with the UX team.</li></ul><p><em>* I want to make a note on the confusion between UI Engineer, UX Engineer, and Front End Engineer. These are often assumed to be the same role. That may or may not be the case, depending on what is in the job description. However, there are some notable differences.</em></p><p><strong><em>UI Engineer</em></strong><em> is the most similar to a Front End Engineer. They’re not entirely the same historically, but the line between the two has become blurry. They will work on the technical side of building the user interface. Working on the UI can easily start to bleed into UX topics as they are tightly coupled, which may be where the confusion arises.</em></p><p><strong><em>UX Engineer </em></strong><em>is the more design-forward of the two. A UXE is a technical role that is intrinsically involved in the user’s experience. They would be the ones to consider “How is the user interacting with this button?”, “How can I make it absolutely clear what this button does”, and “How can I provide the user a better experience when using this button?” The job description of UX Engineer might align more with what you would see under Design Technologist or Design System Engineer.</em></p><p>Over the past several decades, software engineering has dramatically evolved transitioning from the very low-level (assembly and machine language) requiring a deep understanding of the underlying architecture to high-level programming abstracting away the hardware complexities and significantly simplifying the development process. In recent years, another leap in software engineering has been the rise of low-code or even no-code development platforms, frameworks, component libraries, and APIs. Such platforms have democratized product design and development, allowing businesses to rapidly prototype, build, and deploy applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*56LCWJXnHNEMYuVLBXTwhA.jpeg" /><figcaption>The Evolution of Design and Engineering Tools</figcaption></figure><p>As the boundaries between design and engineering blur, I wonder whether the creative mantle will eventually shift to engineering entirely, with design remaining responsible primarily for business needs, research/testing, product management, and cross-functional communication. Or maybe, things will go in the exact opposite direction.</p><p>In the dynamic world of technology, change is the only constant. Roles and responsibilities in previously well-defined and structured disciplines increasingly evolve becoming more fluid and intertwined. As technological advancements continue to reshape our work, the dynamics between design and engineering will likely continue to develop, potentially entirely changing our approach to product development.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=424ba8dda47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[System Design: Chat Application]]></title>
            <link>https://medium.com/@m.romaniiuk/system-design-chat-application-1d6fbf21b372?source=rss-3293b4c743f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1d6fbf21b372</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[coding-interviews]]></category>
            <dc:creator><![CDATA[Mariia Romaniuk]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 08:23:17 GMT</pubDate>
            <atom:updated>2023-06-21T09:04:15.847Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding the architecture and system design of a real-time chat application</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QROz3v7SVkW3yY8_qbDEpQ.png" /></figure><h3>Requirements and Goals of the System</h3><h4>Functional requirements</h4><ul><li><strong>Conversation:</strong> The system should support one-on-one and group conversations between users.</li><li><strong>Acknowledgment:</strong> The system should support message delivery acknowledgment, such as sent, delivered, and read.</li><li><strong>Sharing: </strong>The system should support sharing of media files, such as images, videos, and audio.</li><li><strong>Chat storage: </strong>The system must support the persistent storage of chat messages when a user is offline until the successful delivery of messages.</li><li><strong>Push notifications:</strong> The system should be able to notify offline users of new messages once their status becomes online.</li></ul><h4>Non-functional requirements</h4><ul><li><strong>Low latency: </strong>Users should be able to receive messages with low latency.</li><li><strong>Consistency: </strong>Messages should be delivered in the order they were sent. Also, users must see the same chat history on all of their devices.</li><li><strong>Availability:</strong> The system should be highly available. However, consistency is more important than availability.</li><li><strong>Security: </strong>The system must be secure via end-to-end encryption. We need to ensure that only the communicating parties can see the content of messages. Nobody in between, not even we as service owners, should have access.</li><li><strong>Scalability: </strong>The system should be highly scalable to support an increasing number of users and messages per day.</li></ul><h3>High-Level System Design</h3><p>First, we need to understand how clients and servers communicate. In a chat system, clients can be either mobile or web applications. Clients do not communicate directly with each other. Each client connects to a chat service, which supports all the features we discussed previously:</p><ul><li>Receive messages from other clients.</li><li>Find the right recipients for each message and relay (pass) the message to the recipients.</li><li>If a recipient is not online, it needs to hold the messages for that recipient on the server until they are online.</li></ul><p>Since HTTP is client-initiated, we can’t really send messages from the server to the receiver so we need to think about other techniques used to simulate a server-initiated connection: polling, long polling, and WebSocket.</p><ul><li><strong>Polling</strong> is where the client periodically requests data from the server, generating a high number of requests which is inefficient.</li><li><strong>Long polling</strong> where the server holds the connection open until new data is available, reducing the number of requests and latency.</li><li><strong>WebSocket</strong> is a bidirectional communication protocol that enables real-time communication between the client and server over a single, long-lived connection, providing the lowest latency. It is the most common solution for sending async updates from server to client.</li></ul><p><strong>Step-by-step communication between both clients is as follows:</strong></p><ol><li>User A and User B create a communication channel with the chat server.</li><li>User A sends a message to the chat server.</li><li>When a message is received, the chat server acknowledges back to user A.</li><li>The chat server sends the message to user B and stores the message in the database if the receiver’s status is offline.</li><li>User B sends an acknowledgment to the chat server.</li><li>The chat server notifies user A that the message has been successfully delivered.</li><li>When user B reads the message, the application notifies the chat server.</li><li>The chat server notifies user A that user B has read the message.</li></ol><p><strong><em>* </em></strong><em>For client-server communication </em><strong><em>WebSocket is preferred over HTTP(S) protocol</em></strong><em> since HTTP(S) doesn’t keep the connection open for the servers to send frequent data to a client. With HTTP(S) protocol, a client constantly requests updates from the server, which is resource intensive and causes latency. WebSocket maintains a persistent connection between the client and a server. This protocol transfers data to the client immediately whenever it becomes available. It provides a bidirectional connection used as a common solution to send async updates from a server to a client.</em></p><p>Everything else does not have to be WebSocket. In fact, most features (sign up, log in, user profile, etc) of a chat application could use the traditional request/response method over HTTP. Let’s look at the high-level components of our system. The chat system is broken down into three major categories: stateless services, stateful services, and third-party integration.</p><p><strong>Stateless Services</strong> are traditional public-facing request/response services, used to manage the login, signup, user profile, etc. They sit behind a load balancer whose job is to route requests to the correct services based on the request paths. These services can be monolithic or individual microservices. We do not need to build many of these stateless services by ourselves as there are services in the market that can be integrated easily. The one service that we will discuss more in deep dive is service discovery. Its primary job is to give the client a list of DNS host names of chat servers that the client could connect to.</p><p><strong>Stateful Service </strong>is the only stateful service is chat service. The service is stateful because each client maintains a persistent network connection to a chat server. In this service, a client normally does not switch to another chat server as long as the server is still available. The service discovery coordinates closely with the chat service to avoid server overloading.</p><p><strong>Third-party integration</strong> is for push notifications to inform users when new messages arrived, even when the app is not running.</p><h4>Storage</h4><p>We need to think of which type of database to use: relational databases or NoSQL. We’ll have two types of data in a typical chat system. The first is generic data, such as user profile, settings, and user friends list. This data should be stored in a reliable relational database. We surely need to implement replication and sharding to satisfy availability and scalability requirements.</p><p>The second is unique to chat systems: chat history data. It is important to understand the read/write pattern.</p><ul><li>The amount of data is enormous for chat systems (Facebook has 60 billion messages a day).</li><li>Only recent chats are accessed frequently. Users do not usually look up old chats.</li><li>Although very recent chat history is viewed in most cases, users might use features that require random access to data, such as search, view your mentions, jump to specific messages, etc. These cases should be supported by the data access layer.</li><li>The read-to-write ratio is about 1:1 for 1 on 1 chat apps.</li></ul><p>So I think the key-value store will be a great fit here because:</p><ul><li>Key-value stores allow easy horizontal scaling.</li><li>Key-value stores provide very low latency to access data.</li><li>Relational databases do not handle the long tail of data well. When the indexes grow large, random access is expensive.</li><li>Key-value stores are adopted by other proven reliable chat applications. For example, both Facebook messenger and Discord use key-value stores.</li></ul><h3>Data Models</h3><h4>Message table for 1 on 1 chat</h4><p>The primary key is <strong><em>message_id</em></strong>, which helps to decide the message sequence. We cannot rely on <strong><em>created_at</em></strong> to decide the message sequence because two messages can be created at the same time.</p><h4>Message table for group chat</h4><p>The composite primary key is <em>(</em><strong><em>channel_id</em></strong><em>, </em><strong><em>message_id</em></strong><em>). </em>A primary key is a unique identifier for each row in a database table. A composite primary key consists of two or more columns that together uniquely identify a row. In this case, the composite primary key is composed of two columns: <strong><em>channel_id</em></strong> and <strong><em>message_id</em></strong>. Channel and group represent the same meaning here. <strong><em>channel_id</em></strong> is the partition key because all queries in a group chat operate in a channel.</p><h4>Message ID</h4><p>The <strong><em>message_id</em></strong> is responsible for the order of messages.</p><ul><li>IDs must be unique.</li><li>IDs should be sortable by time, meaning new rows have higher IDs than old ones.</li></ul><p>How can we achieve those two guarantees? The first idea that comes to mind is the “<strong><em>auto_increment</em></strong>” keyword in MySql. However, NoSQL databases usually do not provide such a feature. The second approach is to use a global 64-bit sequence number generator like Snowflake. And the final approach is to use a local sequence number generator. Local means IDs are only unique within a group. The reason why local IDs work is that maintaining message sequences within a one-on-one channel or a group channel is sufficient. This approach is easier to implement in comparison to the global ID implementation.</p><h3>API Design</h3><h4>1. Send a message</h4><p>This API is used to send a text message from a sender to a receiver by making a POST API call to the /messages API endpoint. Generally, the sender’s and receiver’s IDs are their phone numbers.</p><pre>sendMessage(sender_ID, reciever_ID, type, text=none, media_object=none, document=none)</pre><ul><li><strong><em>sender_ID</em></strong> → unique identifier of the user who sends the message.</li><li><strong><em>reciever_ID</em></strong> → unique identifier of the user who receives the message.</li><li><strong>type</strong> → represents whether the sender sends a media file or a document (the default message type is text).</li><li><strong><em>text</em></strong> → contains the text that has to be sent as a message.</li><li><strong><em>media_object</em></strong> → is defined based on the type parameter. It represents the media file to be sent.</li><li><strong><em>document</em></strong> → the document file to be sent.</li></ul><h4>2. Get a message</h4><p>Using this API call, users can fetch all unread messages when they come online after being offline.</p><pre>getMessage(user_Id)</pre><ul><li><strong><em>user_id</em></strong> → unique identifier representing the user who has to fetch all unread messages.</li></ul><h4>3. Upload media or document file</h4><p>We can upload media files via the <strong><em>uploadFile()</em> </strong>API by making a <strong><em>POST</em></strong> request to the <strong><em>/v1/media</em></strong><em> </em>API endpoint. A successful response will return an ID that’s forwarded to the receiver. Let’s say that the maximum file size for media that can be uploaded is 16 MB, while the limit is 100 MB for a document.</p><pre>uploadFile(file_type, file)</pre><ul><li><strong><em>file_type</em></strong> → type of file uploaded via the API call.</li><li><strong><em>file</em></strong> → contains the file being uploaded via the API call.</li></ul><h4>4. Download a document or media file</h4><pre>downloadFile(user_id, file_id)</pre><ul><li><strong><em>user_id</em></strong> → unique identifier of the user who will download a file.</li><li><strong><em>file_id</em></strong> → unique identifier of a file. It’s generated while uploading a file via<em> </em><strong><em>uploadFile()</em> </strong>API call. The <strong><em>downloadFile()</em> </strong>API call downloads the media file through this identifier. The client can find the <strong><em>file_id</em></strong><em> </em>by providing the file name to the server.</li></ul><h3>Detailed Design</h3><h4>WebSocket server</h4><p>One WebSocket server definitely won’t be enough to handle billions of devices, so there should be enough servers to handle this. These services are responsible for providing a port to every online user. So we need a <strong><em>WebSocket manager</em></strong> which basically lays on top of a cluster of the data store (Redis).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EmWwyE1pfaBv3-vW.png" /></figure><h4>Service discovery</h4><p>Also, we’ll need to recommend the best chat server for a client based on their geo-location, server capacity, etc. Apache Zookeeper is a popular open-source one. It registers all the available chat servers and picks the best chat server for a client based on predefined criteria.</p><p>1. User A tries to log in to the app.</p><p>2. The load balancer sends the login request to API servers.</p><p>3. After the backend authenticates the user, service discovery finds the best chat server for User A (server 2) and the server info is returned back to User A.</p><p>4. User A connects to chat server 2 through WebSocket.</p><h4>Sending or receiving messages</h4><p>A WebSocket server also needs to communicate with another service which is a <strong><em>message service</em></strong>. Message service is basically a repository of messages on top of the database cluster. It acts as an interface to the database for other services interacting with the databases. It stores and retrieves messages from the database and deletes them after a specific amount of time (which we can set). And, it exposes APIs to receive messages by various filters, such as user ID, message ID, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_1Ya30s_xHf8nNxY.png" /></figure><p>Now, if user A wants to send a message to user B. Since we have a number of WebSocket servers these users can be connected to different ones. So how does this work:</p><ol><li>User A communicates with the corresponding WebSocket server to which it is connected.</li><li>The WebSocket server associated with user A identifies the WebSocket to which user B is connected via the WebSocket manager. If user B is online, the WebSocket manager responds back to user A’s WebSocket server that user B is connected with its WebSocket server.</li><li>At the same time, the WebSocket server sends the message to the message service and it is stored in the database (in case user B is offline). So the eviction policy for the message to be processed will be first-in-first-out (which makes perfect sense in this case). And when the messages are delivered to the receiver, they are deleted from the database.</li><li>Now, user A’s WebSocket server has the information that user B is connected with its own WebSocket server. Both users communicate with the WebSocket manager to find each other’s WebSocket server.</li><li>If user B is offline, messages are kept in the database. Whenever they become online, all the messages intended for user B are delivered via push notification. Otherwise, these messages are deleted permanently after 30 days.</li></ol><p>In case there is a continuous conversation between both users, many calls are made to the WebSocket manager. And to minimize the latency and reduce the number of these calls, we can add a cache to each WebSocket server so:</p><ul><li>If both users are connected to the same server, the call to the WebSocket manager can be avoided.</li><li>It can also cache the information of recent conversations about which user is connected to which WebSocket server.</li></ul><p>We should also think about the expiration policy — for how long should a WebSocket server cache information? The data in the cache will become outdated if a user gets disconnected and connects with another server.</p><p>In this case, the information will be updated in the WebSocket manager which in turn, will validate the data in the cache used by the WebSocket servers, and the updated data will be sent to the corresponding cache. So, the information in the cache will remain there until it receives an invalid signal from the WebSocket manager.</p><h4>Support for group messages</h4><p>WebSocket servers don’t keep track of groups because they only track active users. But in the group some users could be online and others could be offline. We need to think about other components for group messages, responsible for delivering messages to each user in a group:</p><ul><li>Group message handler</li><li>Group message service</li><li>The message queue <strong>*<em>Kafka</em></strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YbXObcsvcgh2NWqm.png" /></figure><p><strong><em>*Kafka</em></strong><em> is an open-source distributed event streaming platform that is used for building real-time data pipelines and streaming applications. It is designed to handle large volumes of data in real time. It provides a publish-subscribe messaging system that allows applications to send and receive messages in a fault-tolerant, scalable, and reliable manner. Kafka is based on a distributed architecture that consists of multiple nodes or brokers that work together to form a cluster. Producers can send messages to Kafka topics, and consumers can read messages from these topics. Kafka also supports stream processing, which allows for the processing of data streams in real time. Kafka is widely used in the industry for building real-time data pipelines and streaming applications, and it has become an essential tool in the big data ecosystem.</em></p><p>User A wants to send a message to a group with some unique ID — for example, Group/A:</p><ol><li>Since user A is connected to a WebSocket server, it sends a message to the message service for Group/A.</li><li>The group message handler communicates with the group service to retrieve data of Group/A users.</li><li>The message service sends the message to Kafka with other specific information about the group. The message is saved there for further processing. In Kafka terminology, a group can be a topic, and the senders and receivers can be producers and consumers, respectively.</li><li>Now, the group service keeps all information about users in each group in the system. It has all the information about each group, including user IDs, group ID, status, group icon, number of users, and so on. This service resides on top of the MySQL database cluster, with multiple secondary replicas distributed geographically. A Redis cache server also exists to cache data from the MySQL servers. Both geographically distributed replicas and Redis cache help to reduce latency.</li><li>Lastly, the group message handler follows the same process as a WebSocket server and delivers the message to each user.</li></ol><h4>Why use SQL database in our chat app:</h4><ul><li><strong>Structured Data:</strong> Chat services require structured data to manage user conversations, user profiles, and message history. SQL databases provide a structured approach to organizing data that makes it easy to query and manage.</li><li><strong>Consistency: </strong>our service also requires consistency in data storage and retrieval to ensure that messages are delivered reliably and consistently. SQL databases guarantee the consistency of data even when multiple users are accessing it concurrently.</li><li><strong>Scalability: </strong>the ability to scale easily is important as the number of users and messages ever-increasing. SQL databases offer the ability to<strong> *<em>shard</em></strong> data across multiple servers and nodes, making it easier to scale horizontally.</li><li><strong>Reliability: </strong>our chat app needs to be reliable and available 24/7.</li></ul><p><strong>*<em> Sharding (horizontal scaling)</em></strong><em> is the practice of adding more servers. Sharding separates large databases into smaller, more easily managed parts called shards. Each shard shares the same schema, though the actual data on each shard is unique to the shard. User data is allocated to a database server based on user IDs. Anytime you access data, a hash function is used to find the corresponding shard. In our example, user_id % 4 is used as the hash function. If the result equals 0, shard 0 is used to store and fetch data. If the result equals 1, shard 1 is used. The same logic applies to other shards.</em></p><h4>User service</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0iMQzVgW659Zxinv.png" /></figure><h4>Media files</h4><p>Usually, the WebSocket servers are lightweight and don’t support heavy logic such as handling the sending and receiving of media files. So we need to add another service — asset service, which will be responsible for sending and receiving media files. The compressed and encrypted file will be sent to the asset service to store the file on blob storage. The content is loaded onto a CDN if the asset service receives a large number of requests for some particular content.</p><p>For sending media files:</p><ol><li>It first should be compressed and encrypted on the device side.</li><li>The compressed and encrypted file then is sent to the asset service to store the file on *<strong><em>blob storage</em></strong>. The asset service assigns an ID that’s associated with the sender. The asset service can also have a hash for each file to avoid duplication of content on the blob storage. For example, if a user wants to upload an image that’s already there in the blob storage, the image won’t be uploaded. Instead, the same ID is forwarded to the receiver.</li><li>The asset service sends the ID of media files to the receiver via the message service. The receiver downloads the media file from the blob storage using the ID.</li><li>The content is loaded onto a CDN if the asset service receives a large number of requests for some particular content.</li></ol><p><strong><em>* Blob store</em></strong><em> is a storage solution for unstructured data. We can store photos, audio, videos, or other multimedia items there. Every type of data is stored as a blob. It follows a flat data organization pattern where there are no directories, sub-directories, and so on. It’s used by applications with a particular business requirement called write once, read many (WORM), which states that data can only be written once and that no one can change it. Blob store is extensively used by YouTube, Netflix, Facebook, and so on.</em></p><h3>Final Design</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mWxHu_ToM8hD3aTA.png" /></figure><h4>Non-functional Requirements</h4><p>Our non-functional requirements for this design are low latency, consistency, availability, and security. Let’s think of how we can achieve these requirements in our system:</p><p><strong>Low latency:</strong> We can minimize the latency of the system at various levels:</p><ul><li>We can do this through geographically distributed WebSocket servers and the cache associated with them.</li><li>We can use Redis cache clusters on top of MySQL database clusters.</li><li>We can use CDNs for frequently sharing documents and media content.</li></ul><p><strong>Consistency:</strong> The system also provides high consistency in messages with the help of a FIFO messaging queue with strict ordering. However, the ordering of messages would require the Sequencer (component or algorithm that assigns a unique sequence number or timestamp) to provide ID to each message. This ID number helps the system identify the order in which the messages were sent, even if they arrive out of order. For offline users, the Mnesia database stores messages in a queue. The messages are sent later in a sequence after the user goes online.</p><p><strong>Availability:</strong> The system can be made highly available if we have enough WebSocket servers and replicate data across multiple servers. When a user gets disconnected due to some fault in the WebSocket server, the session is re-created via a load balancer with a different server. Moreover, the messages are stored on the Datastore cluster (Mnesia is often used in messaging systems) following the primary-secondary replication model, which provides high availability and durability.</p><p><strong>Security:</strong> The system also provides an end-to-end encryption mechanism that secures the chat between users.</p><p><strong>Scalability: </strong>Due to high-performance engineering (meaning if our system was designed and developed using high-performance engineering principles), scalability might not be a significant issue. However, our proposed system is flexible, as more servers can be added or removed as the load increases or decreases.</p><h3>Trade-offs</h3><h4>The trade-off between consistency and availability</h4><p>According to the *<strong><em>CAP theorem</em></strong>, the system can provide either one or another in the event of a network partition. It is obvious that in our system, the correct ordering of messages is essential. Otherwise, the context of the information communicated between users might change significantly. Therefore, I think availability in our system can take a hit if the network partition occurs.</p><p>*<em> The </em><strong><em>CAP theorem</em></strong><em> (also called Brewer’s theorem) states that a distributed database system can only guarantee two out of these three characteristics: Consistency, Availability, and Partition Tolerance.</em></p><h4>The trade-off between latency and security</h4><p>Low latency is an essential factor in system design that provides a real-time experience to users. However, on the other side, sharing information or data over our chat app might be insecure without encryption. The absence of a proper security mechanism makes the data vulnerable to unauthorized access. So, we can accept a trade-off prioritizing the secure transmission of messages over low latency. For example, in the case of communications involving multimedia, encrypting them in near real-time on the sender device and decrypting them on the receiver side can be taxing for the devices, causing latency.</p><h3>Resource Estimation</h3><p>We need to estimate the storage capacity, bandwidth, and number of servers to support such an enormous number of users and messages.</p><h4>Storage estimation</h4><p>For example, for WatsUp there are more than 100 billion messages shared per day, let’s estimate the storage capacity based on this figure. Assume that each message takes 100 Bytes on average and our servers will keep the messages only for 30 days. So, if the user doesn’t get connected to the server within these days, the messages will be permanently deleted from the server.</p><pre>100 billion/day ∗ 100 Bytes = 10 TB/day</pre><p>For 30 days, the storage capacity would be approximately:</p><pre>30 ∗ 10 TB/day = 300 TB/month</pre><p>Besides chat messages, we also have media files, which take more than 100 Bytes per message. We also have to store users’ information and messages’ metadata — for example, time stamp, ID, and so on. Along the way, we also need encryption and decryption for secure communication (so we’ll need to store encryption keys and relevant metadata). So, to be precise, we need more than 300 TB per month, but for the sake of simplicity, let’s stick to the number 300 TB per month.</p><h4>Bandwidth estimation</h4><p>Since our service will get 10TB of data each day we need to divide this by 86400 which is the number of seconds in the day, and this will give us an<strong><em> incoming bandwidth </em></strong>of 926 Mb/s.</p><pre>10 TB / 86400 ≈  116 MBps</pre><p>To keep it simple, let’s ignore for now the media content like images, videos, documents, and so on. Otherwise, we’ll spend the whole interview on that.</p><p>We also will need the same amount of <strong><em>outgoing bandwidth</em></strong> because the same message from the sender would need to be delivered to the receiver:</p><pre>Total bandwidth: 116 ∗ 2 = 232 MBps</pre><h4>Number of servers estimation</h4><p>Let’s move to the estimation of the number of servers. Let’s say our system handles around 10 million connections on a single server (like WhatsApp) and the total connection per day is 2 billion:</p><pre>N of servers = total connections per day / N of connections per server</pre><pre>2 billion / 10 million = 200 servers</pre><h3>Reference Materials</h3><ul><li><a href="https://www.amazon.com/Designing-Data-Intensive-Applications-Reliable-Maintainable/dp/1449373321">Martin Kleppmann — Designing Data-Intensive Applications: The Big Ideas Behind Reliable, Scalable, and Maintainable Systems</a></li><li><a href="https://medium.com/dev-genius/system-design-blueprint-the-ultimate-guide-e27b914bf8f1">Love Sharma — System Design Blueprint: The Ultimate Guide</a></li><li><a href="https://bytebytego.com/courses/system-design-interview/design-a-chat-system">ByteByteGo — Design A Chat System</a></li><li><a href="https://www.educative.io/courses/grokking-modern-system-design-interview-for-engineers-managers?utm_campaign=system_design&amp;utm_source=google&amp;utm_medium=ppc&amp;utm_content=search&amp;utm_term=course&amp;eid=5082902844932096&amp;utm_term=system%20design%20interview%20course&amp;utm_campaign=%5BNew%5D+System+Design-Search-US+CAN&amp;utm_source=adwords&amp;utm_medium=ppc&amp;hsa_acc=5451446008&amp;hsa_cam=18164799962&amp;hsa_grp=143542821307&amp;hsa_ad=618618230577&amp;hsa_src=g&amp;hsa_tgt=kwd-586801717917&amp;hsa_kw=system%20design%20interview%20course&amp;hsa_mt=b&amp;hsa_net=adwords&amp;hsa_ver=3&amp;gclid=CjwKCAjwv8qkBhAnEiwAkY-ahlX4wDWgLMpnel_Ak7ymaGJntFhgXJm9jM0WL5AgkVcITyupfII3SBoCVr4QAvD_BwE">Educative.io — Grokking Modern System Design Interview</a></li><li><a href="https://github.com/donnemartin/system-design-primer">Donne Martin — System Design Primer</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1d6fbf21b372" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Attention is All You Need]]></title>
            <link>https://medium.com/@m.romaniiuk/attention-is-all-you-need-956d1f28eed3?source=rss-3293b4c743f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/956d1f28eed3</guid>
            <category><![CDATA[self-development]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[focus]]></category>
            <category><![CDATA[self-improvement]]></category>
            <category><![CDATA[flow]]></category>
            <dc:creator><![CDATA[Mariia Romaniuk]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 04:03:56 GMT</pubDate>
            <atom:updated>2023-06-21T04:03:56.880Z</atom:updated>
            <content:encoded><![CDATA[<h4>Fragmented attention: how to regain the ability for deep concentration and clear thinking?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6M0a17VilE6wfvyqVWBhIA.png" /></figure><p>I’d like to begin with a quote from the book “Deep Work”: “Mastering attention management is an essential condition for a fulfilling life, and it’s the key to enhancing nearly every aspect of your personal experience.” I find myself revisiting this subject as I’m troubled by the state of my own attention and the broader societal attention as well. I recently stumbled upon a phrase that resonates with my current sentiment, “I intended to live, but somehow got distracted.” This underlines a simple truth, “Your reality is dictated by what you pay attention to.” When, for example, I spend the morning on my phone without realizing it, my world morphs into what Newport accurately describes as a “buzz of nervous mental energy.” To paraphrase Newport, “The phone world is not the most pleasant world to live in.”</p><p>Recently I read Johan Hari’s book “Stolen Focus,” which I found incredibly insightful and thought-provoking. However, in comparison to “Deep Work,” Hari presents a more left-leaning perspective on the Attention Crisis. According to Hari, the attention problem exists on two levels: individual and systemic. He suggests that our potential for individual change is considerably constrained by systemic issues. He compares this scenario with a polluted atmosphere; the solution isn’t to sporadically don a gas mask, but rather to combat the source of pollution. Hari argues that as long as the business model of tech companies is structured around the monetization of our attention, we, as individuals, can do little on an individual level. Here I disagree with the author — we can still do something.</p><h3>Flow Heals Attention</h3><p>Social media is sometimes referred to as a “Skinner’s Box.” B.F. Skinner, a well-known psychologist, believed that through reward and punishment, positive and negative reinforcement, one can easily manage the behavior of both animals and humans. For instance, his experiment with pigeons, where a mechanism releases seeds based on a particular movement of the pigeon, demonstrated that pigeons can even be trained to play ping-pong. Drawing a parallel to social media, likes and comments serve as a form of positive reinforcement, and we, like Skinner’s creatures, fall for it.</p><p>This manipulative view of human psychology is countered by Mihaly Csikszentmihalyi’s concept of “flow.” Csikszentmihalyi studied the psychological effects of daily activities through an innovative methodology of his time. Research participants were equipped with pagers that periodically signaled them to record their current activity and emotional state. This experiment led Csikszentmihalyi to discover that our finest moments arise when we voluntarily push our body and mind to their limits to achieve something challenging and significant. During a state of flow, we are fully present in the moment, ego dissolves and merges with the task. Flow serves as an antidote to fragmentation, which tends to diminish us, making us feel petty and agitated. Conversely, flow elevates us, leading to deeper insights and a sense of tranquility.</p><p>I’ve observed that if I manage to engage in deep concentration for at least half an hour in the morning — say, reading a long-form piece, essay, article (preferably on paper), working out, or journaling — I find myself more at ease throughout the day and enjoy dedicating time to other activities. Flow heals attention. The more we can incorporate states of flow into our lives, the better we feel. So, how can we encourage this?</p><p>Firstly, we need a clear goal — it could be reading a book, sketching, working out, teaching a child to read, and so on. Secondly, a balance between the task’s difficulty level and our skills is crucial — it should not be so easy as to bore us or too challenging as to induce frustration. Thirdly, internal motivation, or what Csikszentmihalyi referred to as an “autotelic experience,” is essential — flow is an activity that is an end in itself and is performed for its own sake. And lastly, full concentration is vital, as flow is impossible with distractions and multitasking.</p><h3>The Wandering Mind</h3><p>Interestingly, the cover of Cal Newport’s book displays a ‘focus lamp’ — a metaphor for attention originally formulated by William James. When we imagine an efficient worker, we often visualize a person focused on a single task. In school, we were scolded for looking around, being distracted, or “daydreaming”. But the focus is merely one form of attention. Over time, it’s been realized that this so-called “daydreaming,” or mind-wandering, can actually be a productive form of thinking. When we disengage from conscious focus, attention does not disappear but rather diffuses, allowing energy to transfer to other forms of thinking.</p><p>The wandering mind has several advantages. Firstly, it opens up mental space for introspection, decision-making, and long-term goal-setting. Secondly, it’s invaluable for creativity as it catalyzes unexpected connections. As we know, creativity is not about creating something entirely new, but about forming novel associations between already existing elements.</p><p>We generally have an inherent fear of boredom. As French philosopher Blaise Pascal said, “All of humanity’s problems stem from man’s inability to sit quietly in a room alone.” Interestingly, when we talk about disconnecting from distractions, we often imply replacing them with other forms of stimulation. For instance, turning off the phone to immerse in a book. But what if we leave these mental pauses unfilled? It’s a wonderfully pleasant feeling to live within the limits of our attention span. As one expert shared with Johan Hari, constant stimulation can feel like trying to drink from a fire hose, whereas letting the mind wander is like finally drinking from a glass.</p><p>I conducted such an experiment on myself — typically, when I take a shower or clean the house, I always listen to some podcast or a book on my headphones. Now, I leave my phone and headphones aside and simply let my thoughts wander. Surprisingly, this creates a sense of mental space and there’s so much interesting to discover within it.</p><h3>The Habit of Distraction</h3><p>Much has been written and said about habits, but there’s one idea that I consider to be key. It’s known that habits are problem-solving mechanisms. For instance, you come home tired after work, sit down to watch a movie with a glass of wine, relax, and your brain remembers that this is a way to unwind. This is what’s known as the ‘reward value’ of a habit. The higher the reward value, the stronger the habit. The problem is that once established, the reward value is seldom questioned by us. That is, for example, a sweet treat brought us joy in childhood — this reward value got anchored, and now in adulthood, despite the harm, the habit persists. To update the reward value, conscious observation is needed.</p><p>I’ve noticed that my screen time has decreased, and it’s not because I’m making any particular effort, but simply because the negatives of this experience have significantly reduced the reward. This awareness, also through books like Hari’s, helps refresh the reward value of the habit of constant distractions and helps to get rid of it in favor of a more holistic, deep, slow attention. And not because I have strong willpower or there’s some economic value in it, but simply because a deep life is a good life.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=956d1f28eed3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Graphs: The Shortest Path Algorithm]]></title>
            <link>https://medium.com/@m.romaniiuk/graphs-the-shortest-path-algorithm-1de3b451a357?source=rss-3293b4c743f1------2</link>
            <guid isPermaLink="false">https://medium.com/p/1de3b451a357</guid>
            <dc:creator><![CDATA[Mariia Romaniuk]]></dc:creator>
            <pubDate>Fri, 24 Jul 2020 06:01:59 GMT</pubDate>
            <atom:updated>2020-07-24T19:16:21.764Z</atom:updated>
            <content:encoded><![CDATA[<p>Graph theory has many applications. For example, we can use graphs to show how different chemicals are related or to show airline routes. Graphs also used to show the highway structure of a city, state, or country. The edges connecting two vertices can be assigned a non-negative real number, called the <strong>weight of the edge</strong>. If the graph represents a highway structure, the weight can represent the distance between two places or the travel time from one place to another. Such graphs are called <strong>weighted graphs</strong>. At its core, a <strong>weighted graph </strong>is a graph whose edges have some sort of value that is associated with them. The value that is attached to an edge is what gives the edge its <strong>weight</strong>.</p><p>Suppose that the weight of an edge represents the travel time. For example, to plan monthly business trips, a salesperson wants to find the shortest path (that is, the path with the smallest weight) from her or his city to every other city in the graph. Many such problems exist in which we want to find the shortest path from a given vertex, called the <strong>source</strong>, to every other vertex in the graph.</p><p>A weighted graph can be represented with an adjacency list, with one added property: a field to store the cost/weight/distance of every edge in the graph. The edges of a graph in an adjacency list live in the list portion.</p><p>Every element in the linked list can contain two values — the opposite node’s index, which is how we know where this edge connects to, as well as the <strong>weight</strong> that is associated with the edge.</p><p><strong>The Problem</strong></p><p>Suppose you have the following graph structure and you want to know the fastest route between nodes A and E.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oH78IBVOlsbiEPJ_h0fR-g.png" /><figcaption>Weighted Graph Diagram</figcaption></figure><p>Because there are only five nodes on this graph it is pretty easy to quickly look at it and determine the fastest route. But, imagine there were a million nodes on this graph. In that case, we would need a step by step process that a computer could follow to determine the shortest path.</p><p><strong>Dijkstra’s Algorithm</strong></p><p>The overall strategy of the algorithm is as follows:</p><ul><li>Given a starting node, compute the distance of each of its connections (edges).</li><li>Whichever connection is the shortest follow it while keeping a running tally of the total distance traveled along that particular path.</li><li>Repeat until you converge on the final node you’re interested in.</li></ul><p>So, if we’re interested in moving from A to E we start with all the connections of A which are B and C. The distance to C is 2 and the distance to B is 4. 2 is smaller than 4 so we move to node C. We now update our path as A → C and our running total is 2.</p><p>We now examine all of our possible options. Moving from A to B is still 4. Moving from C to D is 4 and moving from C to F is 6 (remember, we add the new connection’s distance to our total — which is the distance from A).</p><p>Since 6is greater than 4, we know C to F is out. We now choose randomly between A → B and C → D. Suppose we choose C → D. We update our path and total — path: A → C → D total: 4.</p><p>We now examine all of our options. A → B is still 4, D → F is 5, and D → E is 7. 4 is the lowest so we chose this route. At this point, hopefully, the general steps of the algorithm make sense. You might also be asking, how should we keep track of the various routes and distances that we are building. The next section will begin to introduce how we can model this in code.</p><p><strong>Implementation</strong></p><p>We’ll need three main data structures:</p><ol><li><strong><em>Distance Hash Table</em></strong>: We’ll need a table that maps each node’s total distance from the starting node. The key will be the node and the value will be its running total.</li><li><strong><em>Priority Queue</em></strong>: When we compare all the possible routes we could take, the priority queue will surface the smallest possible route. In this way, we don’t have to scan an array every time asking, which is the smallest.</li><li><strong><em>Routes Hash Table</em></strong>: We need a way to keep track of the current path we’re building. The key will be the current node we are at and its value will be the node it came from.</li></ol><p><strong>Visualization</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FpVfj6mxhdMw%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DpVfj6mxhdMw&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FpVfj6mxhdMw%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/05f6d0bf8df5aef260da7f073624475d/href">https://medium.com/media/05f6d0bf8df5aef260da7f073624475d/href</a></iframe><p><strong>Code Implementation</strong></p><ol><li>Create a function that accepts a start and endpoint.</li><li>Initialize the distance hash table, the priority queue, the routes hash table, and a path’s array (we’ll push the name of the nodes in here at the end when building our return value).</li><li>Create the starting state for the distance hash table. It should store every node as a key with its initial value set to infinity except for the starting node, which should be 0.</li><li>Create the starting state for the priority queue. It should look similar to the hash table — every node should exist with a starting value of infinity except for the start node — it should be 0. This makes sense b/c our priority queue should be a reflection of our distance hash table.</li><li>Create the starting state for the routes hash which I’ll call previous. It should have a key for every node and the value should be set to null.</li><li>Create a loop that runs as long as there are nodes in the priority queue.</li><li>Dequeue a node, it should be the smallest — b/c of the priority queue.</li><li>If that node is the same as the ending node, we’re done! Loop through the routes hash table and build the final path.</li><li>If not the ending node, find all the connections associated with this node. Add up their totals. If the total is less than what is already stored for it, update it and update the previous hash table.</li><li>Create new nodes which pass in the node name and its new total distance to the priority queue (these are a reflection of the distance hash table).</li><li>This should run until you hit your conditional from step 8. Now, loop through the previous hash table — starting with the final node name (in our case E) — pushing each key into your path array. Reverse the array and return it.</li></ol><p>Here’s the implementation code so you can walk through it.</p><pre>class WeightedGraph {<br>    constructor(){<br>        this.list = {};<br>    }        </pre><pre>    addVertex(v){<br>        if (!this.list[v]) <br>           this.list[v] = [];<br>    }        </pre><pre>    addEdge(v1, v2, priority){<br>        let node1 = new Node(v1, priority);<br>        let node2 = new Node(v2, priority);<br>        if (this.list[v1]) <br>           this.list[v1].push(node2);<br>        if (this.list[v2]) <br>           this.list[v2].push(node1);<br>    }        </pre><pre>    shortestPath(start, end){<br>        // creating the initial data structures<br>        let distances = {};<br>        let nodes = new PriorityQueue();<br>        let previous = {};<br>        let path = [];        <br>        <br>        // setting the initial state for data structures<br>        Object.keys(this.list).forEach(nodeName =&gt; {<br>            if (nodeName === start){<br>                distances[nodeName] = 0;<br>                nodes.enqueue(nodeName, 0);<br>            } else {<br>                distances[nodeName] = Infinity;<br>                nodes.enqueue(nodeName, Infinity);<br>            }<br>            previous[nodeName] = null;<br>        })                </pre><pre>        let smallest;<br>        while (nodes.values.length &gt; 0) {<br>            // smallest value b/c of priority queue logic<br>            smallest = nodes.dequeue().value;<br>            // we&#39;ve reached the end<br>            if (smallest === end){ <br>            // finishing code to determine the path, <br>            // traversing the previous hash table<br>                while (previous[smallest]) {<br>                    path.push(smallest);<br>                    smallest = previous[smallest];    <br>                }<br>                path.push(smallest);<br>                break;<br>            }            <br>    <br>        if (smallest || distances[smallest] !== Infinity) {<br>            // finding each of the node&#39;s connections<br>            this.list[smallest].forEach(node =&gt; {<br>                // computing the new distance - current total <br>                // + new distance<br>                let newestDistance = <br>                        distances[smallest] + node.priority;<br>                let currentDistance = distances[node.value];                                        </pre><pre>                    // a new lower distance, update hash <br>                    // tables and add to queue<br>                    if (newestDistance &lt; currentDistance) {<br>                        distances[node.value] = newestDistance;<br>                        previous[node.value] = smallest;<br>                        nodes.enqueue(node.value, newestDistance);<br>                    }<br>                })<br>            }<br>        }<br>        return path.reverse();<br>    }<br>}</pre><p>In order for this code to work, you’ll also need the setup code for the priority queue and the node class.</p><pre>class Node {<br>    constructor(value, priority){<br>        this.value = value;<br>        this.priority = priority;<br>    }<br>}</pre><pre>class PriorityQueue{<br>    constructor(){<br>        this.values = [];<br>    }        </pre><pre>    swap(idx1, idx2) {<br>        let temp = this.values[idx1];<br>        this.values[idx1] = this.values[idx2];<br>        this.values[idx2] = temp;<br>    }    <br> <br>    enqueue(value, priority) {<br>        let newNode = new Node(value, priority)<br>        // how to find parent elements: Math.floor((n-1)/2)<br>        // smallest priority bubbles up<br>        this.values.push(newNode);<br>        if (this.values.length === 1) <br>            return this;<br>        <br>        let childIdx = this.values.length-1;<br>        let parentIdx = Math.floor((childIdx-1)/2);<br>        let child = this.values[childIdx].priority;<br>        let parent = this.values[parentIdx].priority ;               <br> <br>        while (child &lt; parent &amp;&amp; childIdx &gt; 0){<br>            this.swap(childIdx, parentIdx);<br>            childIdx = parentIdx;<br>            parentIdx = Math.floor((childIdx-1)/2);<br>            parent = this.values[parentIdx];<br>        }        <br>        return this;<br>    }        </pre><pre>    dequeue(){<br>        // how to find child elements: 2n+1, 2n+2<br>        // biggest priority number (least important) sinks down<br>        if (this.values.length === 0) <br>            return undefined;<br>        if (this.values.length === 1) <br>            return this.values.pop();<br>        if (this.values.length === 2) <br>            return this.values.shift();                </pre><pre>        this.swap(0, this.values.length-1);<br>        let removedValue = this.values.pop();<br>        let minChildIdx = null;                </pre><pre>        while (true){<br>            let parentIdx = minChildIdx || 0;<br>            let parent = this.values[parentIdx].priority;<br>            let child1Idx = Math.floor((2*parentIdx)+1);<br>            let child2Idx = child1Idx+1;                        </pre><pre>            if (child1Idx &gt;= this.values.length) <br>                break;<br>            <br>            let child1 = this.values[child1Idx].priority;<br>            let child2 = child2Idx &lt; this.values.length ?          <br>                   this.values[child2Idx].priority : Infinity;    <br>           <br>            let minChild = Math.min(child1, child2)<br>            minChildIdx = this.values[child1Idx].priority === <br>                             minChild ? child1Idx : child2Idx;<br>            <br>            if (parent &gt; minChild) <br>                this.swap(parentIdx, minChildIdx);<br>            else <br>                break;<br>        }        <br>        return removedValue;<br>    }<br>}</pre><p><strong>Resources</strong></p><ol><li><a href="https://www.youtube.com/watch?v=pVfj6mxhdMw">Graph Data Structure — Dijkstra’s Shortest Path Algorithm</a>, Kevin Drumm</li><li><a href="https://www.youtube.com/watch?v=GazC3A4OQTE">Dijkstra’s Algorithm</a>, Computerphile</li><li><a href="https://www.youtube.com/watch?v=zXfDYaahsNA">Dijkstra’s Shortest Paths Algorithm for Graphs</a>, Sesh Venugopal</li><li><a href="http://cs.smith.edu/~streinu/Teaching/Courses/274/Spring98/Projects/Philip/fp/dijkstra.htm">A Single-Source Shortest Path algorithm for computing shortest path</a>, Professor Ileana Streinu</li><li><a href="http://www.cs.yale.edu/homes/lans/readings/routing/dijkstra-routing-1959.pdf">A Note on Two Problems in Connexion with Graphs</a>, E.W. Dijkstra</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1de3b451a357" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>