<?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 Kevin Viglucci on Medium]]></title>
        <description><![CDATA[Stories by Kevin Viglucci on Medium]]></description>
        <link>https://medium.com/@viglucci?source=rss-997e6e217b91------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*04K6TbJDX2mC3MamUnAZsA.jpeg</url>
            <title>Stories by Kevin Viglucci on Medium</title>
            <link>https://medium.com/@viglucci?source=rss-997e6e217b91------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 22:40:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@viglucci/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[Check for an Object in AWS S3 with Ansible]]></title>
            <link>https://levelup.gitconnected.com/check-for-an-object-in-aws-s3-with-ansible-c68e531a4d80?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/c68e531a4d80</guid>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Tue, 07 Feb 2023 14:42:44 GMT</pubDate>
            <atom:updated>2023-02-07T14:42:44.600Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mcQO1D_FU6shJr8jIUW3CA.jpeg" /></figure><p>I’ve been playing a fair bit of <a href="https://www.valheimgame.com/">Valheim</a> recently, and I wanted to take a stab at hosting my own server on AWS EC2. Like any other sane and not overengineered solution, I tried to leverage good infrastructure as code and configuration as code practices so that my server was quickly reproducible (this has been very helpful). Given that, I decided to use Ansible to configure the EC2 instance.</p><p>The rest of this article will describe how I used Ansible to check if save files existed in S3 while configuring the EC2 instance with Ansible.</p><p><strong>Why is it necessary to check if an Object exists?</strong></p><p>The amazon.aws.aws_s3 module will throw an error when downloading a file that doesn&#39;t exist. Because of this, it can be helpful to check if that Object exists before downloading it. Another scenario is that you may want to check if an object exists before replacing it with a new or default object. The sky is the limit!</p><p><strong>1. List Objects in the Bucket</strong></p><p>Ansible provides a helpful module for interacting with S3 buckets. The module is called amazon.aws.s3_object. Using this module, we can list all the Objects in a bucket and then check if a specific Object exists. The module is well documented, and you can find the documentation <a href="https://docs.ansible.com/ansible/latest/collections/amazon/aws/s3_object_module.html">here</a>.</p><p>Using mode: list I list all of the objects in the valheim-saves bucket and store the result in a fact called objects_in_saves_bucket.</p><pre>- name: List Objects in Saves bucket<br>  amazon.aws.aws_s3:<br>    bucket: &quot;valheim-saves&quot;<br>    mode: list<br>  register: objects_in_saves_bucket</pre><p><strong>2. Store the Desire Object Name in a Fact</strong></p><p>Storing the subject Object name in a fact is a convenience step. This way, I could easily change the name of the Object I was looking for and not have to change it in multiple places.</p><pre>- set_fact:<br>    world_save_fwl_file_name: &quot;save-file-name.fwl&quot;</pre><p><strong>Dynamic Object Name Example</strong></p><p>Ansible Lint discourages using interpolation in conditional clauses, such as `when`. When I want to use a dynamic object name, I get around this by storing the object name in a fact, which makes Ansible Lint happy and makes the code more readable.</p><pre>- set_fact:<br>    world_save_fwl_file_name: &quot;{{valheim.world}}.fwl&quot;</pre><p><strong>3. Store the State of the Object in a Fact</strong></p><p>I wanted to store the state of the Object in a fact. This way, I could easily reference the Object’s state in a later conditional.</p><pre>- set_fact:<br>    s3_bucket_has_fwl_save_file: &quot;{{world_save_fwl_file_name in objects_in_saves_bucket.s3_keys}}&quot;</pre><p><strong>4. Download the S3 Object if it Exists</strong></p><p>If the value of s3_bucket_has_fwl_save_file is true, then we will download the Object from S3 into the desired location.</p><pre>- name: Download World Save FML File from S3<br>  when: s3_bucket_has_fwl_save_file<br>  amazon.aws.aws_s3:<br>    bucket: &quot;valheim-saves&quot;<br>    object: &quot;{{ world_save_fwl_file_name }}&quot;<br>    dest: &quot;ubuntu/valheim/saves/worlds_local/{{world_save_fwl_file_name}}&quot;<br>    mode: get</pre><p><strong>Putting it all together</strong></p><p>After putting it all together, we have the following playbook with steps that will check if an object exists in an S3 bucket, and if it does, download it to the host.</p><pre>- name: List Objects in Saves bucket<br>  amazon.aws.aws_s3:<br>    bucket: &quot;valheim-saves&quot;<br>    mode: list<br>  register: objects_in_saves_bucket<br><br>- set_fact:<br>    world_save_fwl_file_name: &quot;save-file-name.fwl&quot;<br><br>- set_fact:<br>    s3_bucket_has_fwl_save_file: &quot;{{world_save_fwl_file_name in objects_in_saves_bucket.s3_keys}}&quot;<br><br>- name: Download World Save FML File from S3<br>  when: s3_bucket_has_fwl_save_file<br>  amazon.aws.aws_s3:<br>    bucket: &quot;valheim-saves&quot;<br>    object: &quot;{{ world_save_fwl_file_name }}&quot;<br>    dest: &quot;ubuntu/valheim/saves/worlds_local/{{world_save_fwl_file_name}}&quot;<br>    mode: get</pre><p><strong>Conclusion</strong></p><p>I hope this article was helpful. If you have any questions or comments, don’t hesitate to get in touch with me via any of my social media <a href="https://linktr.ee/viglucci">links</a>. Thanks for reading!</p><p><em>Originally published at </em><a href="https://viglucci.io/articles/check-for-an-object-in-aws-s3-with-ansible">https://viglucci.io/articles/check-for-an-object-in-aws-s3-with-ansible</a><em>.</em></p><h3>Level Up Coding</h3><p>Thanks for being a part of our community! Before you go:</p><ul><li>👏 Clap for the story and follow the author 👉</li><li>📰 View more content in the <a href="https://levelup.gitconnected.com/?utm_source=pub&amp;utm_medium=post">Level Up Coding publication</a></li><li>🔔 Follow us: <a href="https://twitter.com/gitconnected">Twitter</a> | <a href="https://www.linkedin.com/company/gitconnected">LinkedIn</a> | <a href="https://newsletter.levelup.dev/">Newsletter</a></li></ul><p>🚀👉 <a href="https://jobs.levelup.dev/talent/welcome?referral=true"><strong>Join the Level Up talent collective and find an amazing job</strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c68e531a4d80" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/check-for-an-object-in-aws-s3-with-ansible-c68e531a4d80">Check for an Object in AWS S3 with Ansible</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to System Design Interviews]]></title>
            <link>https://levelup.gitconnected.com/introduction-to-system-design-interviews-56d4cfa0ee36?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/56d4cfa0ee36</guid>
            <category><![CDATA[system-design-interview]]></category>
            <category><![CDATA[interviewing]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Thu, 30 Dec 2021 18:45:28 GMT</pubDate>
            <atom:updated>2022-01-03T14:37:40.651Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*JOcJp9sn9wdgC3Op4dj7Cw.png" /></figure><p>This article will overview practices and areas to focus on when navigating a systems design interview at a high level. I expect this information to be most helpful to engineers in the 1–3 years of experience range or those who have never done a systems design interview.</p><p>Additionally, this article is expected to be used as a jumping-off point, and readers will likely need to leverage other resources to dig deeper into the referenced concepts and terms.</p><h3>What you can expect</h3><p>The shape of a system design interview will likely depend heavily on the company you are interviewing with and the level of the role you have applied for. For instance, an intern or an associate-level candidate might be asked to diagram how multiple classes or modules in a system would interact with each other. In contrast, a more experienced candidate might be asked to design an entire distributed system.</p><h4>Whiteboarding</h4><p>These interviews are generally conducted in a “whiteboard” style, where the interviewer will ask the candidate to present their answer as a diagram. Before the increased prevalence of remote work, this would be conducted on a physical whiteboard; however, as more of the engineering workforce moves to remote work, these interviews are more commonly being performed with tools like <a href="https://excalidraw.com/">Excalidraw</a>, <a href="https://www.tldraw.com/">tldraw</a>, <a href="https://app.diagrams.net/">diagrams.net</a>, and similar online whiteboarding tools. Ideally, the employer will let you know which tools they use for their interviews, and I highly recommend familiarizing yourself with the tool ahead of time. If the employer doesn’t let you know which tool they expect you to use, don’t fret, the interviewer shouldn’t be grading your proficiency with using it.</p><h4>Questions</h4><p>System design questions are designed to understand a candidate’s ability to think deeply about systems and their requirements. These questions generally require a candidate to talk about a system they’ve already worked in, or more commonly, about a theoretical scenario.</p><p>Below are examples of questions that I’ve been asked, others have been asked, or that I’ve asked myself:</p><ul><li>Can you describe a system you’ve worked in recently?</li><li>How would you design the backend for a social media app?</li><li>How would you design the system for a parking garage?</li><li>How would you design an e-commerce site?</li><li>How would you design the content management system for a large blog?</li></ul><p>For specialized industries, an interviewer might ask you a question specific to the domain they operate in, so it wouldn’t hurt to understand some of the complexities of their industry. However, it is just as likely that an interviewer will ask you a generic question, so try not to deep dive too heavily into specialized solutions during your preparation.</p><h3>Prepare for the interview</h3><p>The systems design interview can and should be something you deliberately prepare for, just like any other interview.</p><p>An easy way to practice systems design is to diagram the system you are currently working in and identify the components or areas that are undefined or unknown to you. This exercise should help you identify additional areas of preparation. For instance, your system may use a specific type of database or leverage a cloud provider for block storage. Do you know why the original designers chose a particular database technology? Or the benefits and tradeoffs of block storage? Looking into these and related topics more deeply should be part of your interview preparation.</p><h4><strong>Your current work</strong></h4><p>If the system you are currently working in isn’t very complex or exciting, you may be inexperienced and thus disadvantaged when designing a system from scratch. If this applies to you, it is recommended to spend time answering some of the example questions above, watching mock interviews on platforms like YouTube, and even asking your friends or trusted colleagues to run a mock interview with you.</p><h3>Seek out the customer</h3><p>A system is only helpful if it serves a customer’s needs.</p><h4>Identify the customer</h4><p>A “customer” is any user of the system. These “customers” could be the actual human being using the mobile app that interacts with your system, or they could be other services inside a company’s microservices architecture. As the system designer, you will need to ask yourself, “who is my primary customer?”, and then keep the customer in mind as you design the system.</p><p>It will be vital that you identify who the primary customer of the system is and what requirements those customers have of the system. If it is not apparent who the customer is during the interview, it is recommended to be direct and ask the interviewer, “Who is the primary customer of this system?”. The interviewer should be receptive to these types of questions.</p><p>Additionally, you can identify the primary customer by making assumptions based on statements made by the interviewer. For instance, if the interviewer asks you to “design TikTok” (a popular video-sharing app), you could assume that the customers are global users who primarily interact with the system using their smartphones. Once you think you know who the primary customer is, you should validate this assumption with the interviewer; “Is it safe to assume that my primary customer is global users who are using a smartphone application?”.</p><h3>Identify customer needs</h3><p>The “needs” of the customer can generally be defined as either “functional requirements” or “non-functional requirements.” It is imperative to identify and validate requirements (both functional and non-functional) with the interviewer before you start providing your solution.</p><h4>Functional requirements</h4><p>Generally speaking, you should start by defining the system’s functional requirements, and your interviewer should be receptive to your questions about these requirements. For instance, given the question to “design TikTok,” you might ask your interviewer if the below list of functional requirements satisfies the customer’s needs. The interviewer will likely reply, “looks great to me!” and if not, you should try to dig in on what functional requirements you might have missed.</p><ul><li>upload short videos (length &lt;= 3 minutes)</li><li>view a “feed” of videos</li><li>“like” videos</li><li>comment on videos</li></ul><p>As you dig into your system design, these functional requirements should also expand to include the fundamental ways they will be satisfied. For example, it would be a good idea to list out the various API endpoints needed to satisfy each requirement and maybe even which database structures (tables, documents, etc.) might be required to support those API endpoints. Later on, we’ll touch a bit more on when you should go into detail and also when you should leave things vague.</p><h4>Non-functional requirements</h4><p>Along with functional requirements, non-functional requirements should be identified and vetted with the interviewer before you dig into or decide on system architecture and start creating a diagram. These non-functional requirements could include concepts such as:</p><ul><li>High Availability</li><li>Low Latency</li><li>Eventually Consistent (or Strongly Consistent)</li></ul><p>When determining which of these are relevant to your system, you should always ask yourself how this requirement would serve or impact your customer (the end-user). For example, in the question to “design TikTok,” you might presume that this system could support an architecture that is “Eventually Consistent.” You could argue that it is more important that users can quickly access videos in their feed than for those videos to be the latest or most up-to-date. This argument would suggest that eventual consistency is sufficient.</p><p>When making these arguments or assumptions, you should again validate them with your interviewer. If you fail to validate your assumptions, you may be leaving yourself open to a “curveball” later if the interviewer decides to introduce a constraint contrary to an assumption you made and that your design does not support.</p><p>To validate your assumptions, you may pose the question to your interviewer; “Is it safe to assume that it is more important for the video feed to load quickly than it is for the videos to be the most up to date?”.</p><h3><strong>Knowing the appropriate level of detail</strong></h3><p>A common misstep when answering system design questions is when you provide too much or too little detail. Knowing and ascertaining the correct level of detail expected from your interviewer can be vital to answering your question correctly and sufficiently. Remember that interviews are a two-way conversation between the candidate and the interviewer, and becoming comfortable asking these questions will make you more successful. When describing a particular component of the system, take a moment to pause and ask your interviewer, “is this the level of detail you were expecting, or would you like me to give more or less?”.</p><p>For example, prematurely giving too much detail can hinder you, especially when digging deep on a particular portion of the system in a sufficiently more detailed way than others. For example, the chances are that the system you are designing will require some database or data storage, and you might be eager to blurt out the first database technology that comes to mind, or maybe whichever is your favorite. Unless you’ve established with the interviewer that they are interested in these finer details, try your best to avoid doing this. If you feel the urge to recommend a specific solution, be sure to confirm with the interviewer if they would like those details at that time, but it can also be advantageous to defer that decision.</p><p>By avoiding specifics where they aren’t yet necessary, you allow yourself the flexibility to make this decision later when you potentially have more information. You also avoid showing a potential bias towards a solution or technology that may not fit the system’s requirements. If you do go as far as to state that the database will be a NoSQL database, and even worse, will specifically use Cassandra, you’ve made a strong indication that you think these technologies would provide significant value to the system. The interviewer would be well within their rights to go deep on questioning these decisions.</p><h3><strong>Don’t show up with a solution</strong></h3><p>You’ve likely worked in a few different architectures, and you might even have a favorite design or pattern that you think works best. Experience and opinions are great, but this can be a trap when answering system design questions. It is best to avoid approaching systems with rigid pre-existing solutions or designs.</p><p>For example, suppose you are a big fan of event-driven architectures and are already set on or fantasizing about how you’ll apply this pattern to whichever scenario the interviewer describes. In that case, you’ll quickly fall short when the functional or non-functional requirements of the system don’t lend themselves to the limitations of your predetermined solution.</p><p>Rather than showing up with an architecture already in mind, it is best to understand standard components and approaches and where they can be employed to satisfy different requirements of any given scenario. While the list below is not comprehensive, and the best components and approaches will vary heavily based on the system, it is recommended to understand where each offers value and which tradeoffs they present. These topics are likely to be expected knowledge for mid-level and higher backend engineering interviews.</p><ul><li>Vertical vs. Horizontal Scaling</li><li>Monolith vs. Microservices Architecture</li><li>Database Approaches (Relational, NoSQL, Graph)</li><li>Event/Message Queues</li><li>Load Balancers</li><li>Block/Cloud Storage</li><li>Content Delivery Networks (CDN)</li><li>Serverless/Lambdas</li></ul><h3>Next Steps</h3><p>I hope this article gave you some insights into what to expect from a systems design interview and strategies for successfully navigating them. As stated at the beginning, this article likely isn’t where your preparation ends but where it has just started. I highly recommend digging deeper into the above concepts via other resources and watching a mock system design interview (or ten) to gain broader exposure to common questions and suitable approaches.</p><p>If you landed on this article while preparing for an upcoming interview, I wish you the best of luck 😊. Please feel free to leave any questions/comments below, and if you enjoyed this article, check out my other <a href="https://linktr.ee/viglucci">social media accounts</a>!</p><p><em>Originally published at </em><a href="https://www.viglucci.io/introduction-to-system-design-interviews">viglucci.io</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56d4cfa0ee36" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/introduction-to-system-design-interviews-56d4cfa0ee36">Introduction to System Design Interviews</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to polyfill Buffer with Webpack 5]]></title>
            <link>https://levelup.gitconnected.com/how-to-polyfill-buffer-with-webpack-5-1b6559ab87b8?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b6559ab87b8</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[buffer]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[polyfill]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Tue, 21 Sep 2021 04:27:24 GMT</pubDate>
            <atom:updated>2021-09-22T13:06:02.243Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*APNBE-RyWzei_WzwElEN1g.jpeg" /></figure><p><a href="https://nodejs.org/api/buffer.html">Buffer</a> is a core Node.js API useful when working with binary data. This article will briefly overview how to polyfill the Buffer API for browser environments with Webpack 5.</p><h3>Why do we need to polyfill Buffer?</h3><p>When working in the context of a browser environment, Node.js APIs, such as <a href="https://nodejs.org/api/buffer.html">Buffer</a>, aren’t available. There are sometimes comparable APIs available in the browser environment. However, the author of 3rd party libraries and code you may be using would have had to either replace the Node.js specific APIs they are using with the browser versions or provide another mechanism to provide your API to satisfy the libraries’ need.</p><p>Unfortunately, library authors often do not consider browser environments, or their library may not have been intended to be used in a browser environment. In these cases, it is popular to use a build tool such as Webpack to replace the Node.js specific APIs used by the library with a version that provides a browser environment compatible API, known as <a href="https://developer.mozilla.org/en-US/docs/Glossary/Polyfill">polyfilling</a>.</p><h3>Webpack v5</h3><p>Before Webpack v5, the polyfilling of many Node.js APIs would be performed automatically. With v5, <a href="https://webpack.js.org/blog/2020-10-10-webpack-5-release/#automatic-nodejs-polyfills-removed">Webpack will no longer polyfill Node.js APIs</a> automatically.</p><h3>Solving the Problem</h3><h4>Install a polyfill</h4><p>First, we will need to install or otherwise provide a browser-compatible Buffer implementation. For my needs, I have found the <a href="https://www.npmjs.com/package/buffer">feross/buffer</a> package to be suitable.</p><p>The below command will install buffer as a dev dependency.</p><pre>npm install -D buffer</pre><h4>Configure Webpack Fallback</h4><p>The Webpack resolve.fallback configuration option allows us to configure Webpack to leverage the provided package as a &quot;fallback&quot; for APIs which are not natively available in the target environments that Webpack is building for (ie, a Browser).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40a3d7231fd181ba6aa385c610051c4c/href">https://medium.com/media/40a3d7231fd181ba6aa385c610051c4c/href</a></iframe><p>The / at the end of buffer/ may appear strange to you, as it did to me. However, it is recommended by the <a href="https://www.npmjs.com/package/buffer#usage">buffer documentation</a> because of how the Node.js module lookup algorithm works.</p><blockquote><em>To require this module explicitly, use require(‘buffer/’) which tells the node.js module lookup algorithm (also used by browserify) to use the npm module named buffer instead of the node.js core module named buffer!</em></blockquote><h4>Configure Webpack ProvidePlugin</h4><p>The Webpack ProvidePlugin provides a mechanism for injecting a module/value as a replacement/API for global variables that would otherwise dbe undefined. For instance, in Node.js you can leverage the Buffer class from the global namespace without any import or require statements. The&#39; Buffer&#39; class would be&#39; undefined in a browser environment and without the ProvidePlugin.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20ef8a172e29c585afb63c2e00308c08/href">https://medium.com/media/20ef8a172e29c585afb63c2e00308c08/href</a></iframe><p>We can provide a compatible implementation of the Buffer class via the Webpack configuration plugins array to overcome this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/27d91c7941fb9abd6c68720b17d0f375/href">https://medium.com/media/27d91c7941fb9abd6c68720b17d0f375/href</a></iframe><p>The provided array ([&#39;buffer&#39;, &#39;Buffer&#39;]) informs the webpack.ProvidePlugin to set the global value of Buffer to the Buffer export from the buffer package.</p><p>For example:</p><p>const Buffer = require(‘buffer/’).Buffer;</p><h4>All together</h4><p>Below is an example of the combined relevant parts of your Webpack configuration to polyfill the Buffer class using Webpack v5.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f301ef3fe37c0605c826adbd31de32df/href">https://medium.com/media/f301ef3fe37c0605c826adbd31de32df/href</a></iframe><h3>Conclusion</h3><p>Now that you’ve configured Webpack to polyfill the Buffer class globally, you should be able to reference and create an instance of the Buffer class without the pesky Uncaught ReferenceError: Buffer is not defined error. Additionally, any reference to Buffer in libraries included in your &quot;bundle&quot; should now also reference the provided polyfill.</p><p>Lastly, don’t forget to let me know in the below comments (or on Twitter) if this tutorial helped you in any way!</p><p><em>Originally published at </em><a href="https://viglucci.io/how-to-polyfill-buffer-with-webpack-5">https://viglucci.io/how-to-polyfill-buffer-with-webpack-5</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b6559ab87b8" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/how-to-polyfill-buffer-with-webpack-5-1b6559ab87b8">How to polyfill Buffer with Webpack 5</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Redis Clients in Node.js with Testcontainers Node]]></title>
            <link>https://levelup.gitconnected.com/testing-redis-clients-in-node-js-with-testcontainers-node-8221aafffc57?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/8221aafffc57</guid>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 19:59:29 GMT</pubDate>
            <atom:updated>2021-03-07T14:51:23.036Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*m_-xGC34UE18lgSzJXxjgA.jpeg" /></figure><h3>Write unit tests that consume a real Redis with Testcontainers Node and Docker.</h3><p>Automated testing is an essential aspect of ensuring the quality of any software product. However, it can often be challenging to test systems that rely on databases or other external resources.</p><p>Luckily, <a href="https://www.testcontainers.org/">Testcontainers</a> is a great project that makes setting up external resources more comfortable by providing a programmatic interface to run Docker containers in testing scenarios. In this article, we’ll be looking at a community port of Testcontainers for Node.js (<a href="https://www.npmjs.com/package/testcontainers">testcontainers-node</a>), and how we can run tests that rely on both a single Redis and a Redis Cluster.</p><p>The examples below will leverage <a href="https://www.npmjs.com/package/mocha">mocha</a> as a test runner, <a href="https://www.npmjs.com/package/chai">chai</a> as an assertion library, and <a href="https://github.com/luin/ioredis">ioredis</a> as our backing Redis client.</p><p>Before you go any further, you can skip this article altogether and go straight to some <a href="https://github.com/viglucci/testcontainers-node-redis-example">working examples on GitHub</a> if that’s more your style.</p><h3>Testing against a single Redis</h3><p>Testing against a single Redis instance is exceptionally straightforward.</p><p>First, we will define a describe block with a before hook. In our before hook, we will create our Docker container that will run Redis, and we will also make our Redis client instance. The before hook is run before any tests are invoked.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33bdd92f51b3d12ec3112409f231687f/href">https://medium.com/media/33bdd92f51b3d12ec3112409f231687f/href</a></iframe><p>Once we have our Docker container and Redis client created, we will define an after hook to clean up the resources created in the before hook. The after hook is called when all tests are done executing.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2123af755889e43e96714b0e24c30cce/href">https://medium.com/media/2123af755889e43e96714b0e24c30cce/href</a></iframe><p>Now that our Docker container and Redis client are created, we can write a test that will invoke a command against the running Redis.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71dfd175ce348b9f868aa70ab86a2f4c/href">https://medium.com/media/71dfd175ce348b9f868aa70ab86a2f4c/href</a></iframe><p>Putting it all together, we now have a test that can invoke commands against a running Redis instance and perform assertions on the results.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a77c4b4efeaa5df7ae484188f3e20eb5/href">https://medium.com/media/a77c4b4efeaa5df7ae484188f3e20eb5/href</a></iframe><h3>Testing against a Redis Cluster</h3><p>Testing against a Redis Cluster can be a bit more complicated than against a single Redis. This is primarily because the Docker container’s local network will not map to the same IP and ports as on the host machine. Still, luckily the ioredis library supports the needed configuration to make it possible.</p><p>Using our before hook from the previous example, we will need to make a few small changes to run a Redis cluster rather than a single Redis in our Docker container. These changes include:</p><ul><li>Changing our Redis Docker image to grokzen/redis-cluster.</li><li>Creating a Docker network.</li><li>Creating a list of Redis nodes to connect to.</li><li>Create a <a href="https://en.wikipedia.org/wiki/Network_address_translation">NAT</a> map to map from the internal Docker network to the host network.</li></ul><p>It is necessary to create a NAT map as once our backing Redis client is connected to any node in the cluster; it will attempt to auto-discover any other nodes that belong to the cluster. Unfortunately, when the client discovers new nodes, the nodes will be referenced by local addresses to the Docker container rather than the host machine. The NAT map will allow the client to properly translate the internal Docker address to an available address on the host machine.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9062c01f44dadea4ab01b656bb2aa900/href">https://medium.com/media/9062c01f44dadea4ab01b656bb2aa900/href</a></iframe><p>With our Redis cluster container running and our Redis.Cluster client created, we now need to make sure we remember to add our newly created network resource to our after hook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7849e4e4ce79f0f85981313eb460a34e/href">https://medium.com/media/7849e4e4ce79f0f85981313eb460a34e/href</a></iframe><p>Everything from this point forward is the same as consuming a single Redis. You can see it all put together below.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae794747a7f7574647bbdf1cee279fe4/href">https://medium.com/media/ae794747a7f7574647bbdf1cee279fe4/href</a></iframe><p>Now that you are testing your applications with greater confidence using containers, don’t forget to let me know if you found this article helpful! I appreciate every like, comment, or question you may have to offer!</p><p><em>Originally published at </em><a href="https://viglucci.io/testing-redis-clients-in-nodejs-with-testcontainers-node">https://viglucci.io/testing-redis-clients-in-nodejs-with-testcontainers-node</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8221aafffc57" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/testing-redis-clients-in-node-js-with-testcontainers-node-8221aafffc57">Testing Redis Clients in Node.js with Testcontainers Node</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reactive Streams in JavaScript with RSocket Flowable]]></title>
            <link>https://levelup.gitconnected.com/reactive-streams-in-javascript-with-rsocket-flowable-683097ff91eb?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/683097ff91eb</guid>
            <category><![CDATA[rsocket]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactive-streams]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Sun, 21 Jun 2020 14:39:02 GMT</pubDate>
            <atom:updated>2020-06-21T14:39:02.626Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*-F82T8-BWOMjye7rc_AVCg.png" /></figure><p><em>Message streaming, back-pressure, cancellation, and async programming in JavaScript with rsocket-flowable.</em></p><p>When programming async operations, JavaScript developers are generally at least familiar with Promises, async/await, and callbacks. However, newer async models such as ReactiveX (<a href="https://github.com/ReactiveX/rxjs">RxJS</a> in JavaScript), are not quite as popular. In this article, we dig into something similar but slightly different to RxJS; a Reactive Streams implementation called <a href="https://github.com/rsocket/rsocket-js/blob/master/docs/03-flowable-api.md">RSocket Flowable</a> (rsocket-flowable on npm).</p><h3>Core Concepts</h3><p>At the core of RSocket Flowable is the Observer Pattern, implemented in rsocket-flowable via the <strong>Single</strong> and <strong>Flowable</strong> interfaces.</p><blockquote><em>The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods. </em><a href="https://en.wikipedia.org/wiki/Observer_pattern"><em>https://en.wikipedia.org/wiki/Observer_pattern</em></a></blockquote><h3>Single and Flowable Interfaces</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f7333a3782ac926cc2cb853797837d01/href">https://medium.com/media/f7333a3782ac926cc2cb853797837d01/href</a></iframe><p>The Single is an observable interface that supports the following interactions:</p><ul><li>emit a single value via the subscriber.onComplete callback</li><li>emit an error value via the subscriber.onError callback</li><li>cancellation via the cancel callback passed to observers through the onSubscribe callback</li></ul><p>Apart from cancellation, these operations should feel familiar as they are mostly the same as interacting with Promises, as promises can only ever resolve or reject.</p><h4>Single Example</h4><p>A practical example of consuming the Single interface would be wrapping a promise API/operation, such as the fetch API. In the below case, we do just that; we create a new instance of Single, which when subscribed to will call to the Starwars API to retrieve data about Luke Skywalker.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/40a61865d42854594f952f264518326c/href">https://medium.com/media/40a61865d42854594f952f264518326c/href</a></iframe><p>The Flowable is an observable interface that supports the following interactions:</p><ul><li>emit a single value via the subscriber.onComplete callback</li><li>emit one or more values via the subscriber.onNext callback when the subscriptions <strong>request callback</strong> is invoked</li><li>emit one or more error values via the subscriber.onError callback</li><li>cancellation via the cancel callback passed to observers through the onSubscribe callback</li></ul><p>Flowable differs from Single on a fundamental level in that we expect Flowable to emit one or more values. Single is only ever supposed to emit a single or no value. Additionally, Flowable supports the concept of back-pressure.</p><p>From the Reactive Manifesto:</p><blockquote><em>… back-pressure is an important feedback mechanism that allows systems to gracefully respond to load rather than collapse under it </em><a href="https://www.reactivemanifesto.org/glossary#Back-Pressure"><em>https://www.reactivemanifesto.org/glossary#Back-Pressure</em></a></blockquote><p>The concept of back-pressure isn’t exactly unique to rsocket-flowable, but it is simpler compared to the back-pressure support provided through RxJS. In the simplest terms, Flowable’s back-pressure support allows for an observer to control the rate at which an observable emits or “publishes” values. To support this, <strong>the Flowable interface accepts a subscriber that must implement a request method</strong>. This request method acts as a callback that is responsible for “publishing” values as requested by an observer.</p><p>The request method is responsible for publishing data at the rate requested by an observer, with the observer controlling the flow of data by passing an int value representing the number of events it can handle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a136239d53a54143ad2d863a603a8e2/href">https://medium.com/media/2a136239d53a54143ad2d863a603a8e2/href</a></iframe><p>In this example, calling sub.request(3) would result in onNext() being called with the values 0, 1, 2.</p><p>For a more complex “real world” usage example, read the detailed explanation of an algorithm leveraging Flowable labeled “Flowable Code Example Explanation,” or jump straight the corresponding code sample labeled “Flowable Code Example.”</p><p>Below we’ve implemented a Flowable publisher that will emit data retrieved from the Starwars API for every movie that contains the character Luke Skywalker. To accomplish this, we implement the request method of the subscription object passed to filmsSubscriber.onSubscribe() that roughly follows the following algorithm:</p><p>When the request method is invoked for the first time:</p><ul><li>Fetch data about Luke Skywalker from the Starwars API and destructure the array of films from the response. Save the collection of films to a pendingFilms variable so that we can reference it on subsequent calls to request .</li></ul><p>When the request method is invoked for the first time, and on every subsequent call to request:</p><ul><li>Loop over each URL in the pendingFilms array.</li><li>Break the loop if we have requested the number of movies that the observer requested (requestedFilmsCount).</li><li>Break the loop if data for all of the movies is loaded.</li><li>Retrieve a newURL for a movie from the pendingFilms list.</li><li>Fetch the data about the movie removed from the pendingFilms list, and add the resulting promise to the unsettled promises array (fetches).</li><li>Once the promise resolves, pass the resulting data to filmsSubscriber.onNext(filmData).</li><li>If the promise rejects, pass the resulting error to filmsSubscriber.onError(err).</li><li>Once all the promises saved to the unsettled promises array (fetches) have settled, check if we still have movies we haven&#39;t loaded data for yet.</li><li>If there are movies that still haven’t loaded data for yet, do nothing and wait for the observer to perform a subsequent call to request on its subscription.</li><li>If there are no more movies waiting to be loaded, call filmsSubscriber.onComplete(), which will signify to the observer that all possible data is loaded.</li></ul><p>This algorithm is substantially more complex than the more straightforward case of leveraging Single to forward the result of a Promise. However, the support for controlling the rate at which we pull additional data, along with the backing for cancellation (with small adjustments), makes the added complexity of Flowable a worthwhile tradeoff.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/af8fbc693e6d05a1867e31dfa40fe58b/href">https://medium.com/media/af8fbc693e6d05a1867e31dfa40fe58b/href</a></iframe><h3>Lazy Observables</h3><p>The observable interfaces implemented by rsocket-flowable are “lazy,” meaning that no “work” begins until an observer subscribes to the observable. These observables can also be referred to as “cold observables,” which is in contrast to a “hot observable.” When working with a hot observable, the observable may emit values regardless of the presence of any observers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a814c1b2d546adf67e7041c27a44bff8/href">https://medium.com/media/a814c1b2d546adf67e7041c27a44bff8/href</a></iframe><p>In contrast, you may already be familiar with the concept of “eager” or “hot” interfaces in the form of Promises. For promises, the callback passed to the Promise constructor is invoked as soon as the Promise instance is created (or on the next tick of the event loop if you want to get specific).</p><p>If a tree falling in the woods was a hot observable, it would make sound regardless of if anyone was around to hear it or not.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d239435d5fe5ad3ed7bf47a8be50bf46/href">https://medium.com/media/d239435d5fe5ad3ed7bf47a8be50bf46/href</a></iframe><p>In the above example, the setTimeout method in the callback passed to the Promise constructor is invoked whether the .then() prototype method is invoked or not. You can verify this for yourself by copying the above example into your browser&#39;s dev tools console, where you will see that a console logline printed immediately, followed by a random int value about one second later.</p><h3>Cancellation</h3><p>Cancellation is a powerful feature of observable interfaces, such as rsocket-flowable. Cancellation allows for an observer to indicate to the observable that they are no longer interested in the result of any operations which are ongoing. Cancellation is useful when programming user interfaces with frameworks such as ReactJS, where being able to cancel in-flight async operations is essential for cleaning up state to avoid side effects when unmounting components. Cancellation support is also useful when implementing stateful web services with protocols such as WebSockets, where a client could terminate their connection at any time, and continuing to perform operations on their behalf after they’ve disconnected likely doesn’t make sense.</p><p>In the example below, we create an instance of a Flowable that will emit an integer value until canceled, with a subscriber requesting a random number of ints every 500 milliseconds (half a second). The subscriber will additionally cancel the stream of ints after three seconds. This example is similar to how you could implement a timeout for an async operation, such as a network request or file read.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d7e07cd32df45e64093c053000c4cca/href">https://medium.com/media/8d7e07cd32df45e64093c053000c4cca/href</a></iframe><p>It is essential to understand that canceling an observable stream only instructs the observable that the subscriber no longer cares to receive updates, it does not automatically cancel any operations which the publisher may have been performing. If it is vital for your observable to react to being canceled, then you can implement the subscription.cancel callback to perform cleanup as needed.</p><p>Lastly, with rsocket-flowable@0.0.14, to avoid the below TypeError, you must implement the cancel callback on the publisher if you intend to invoke cancel from a subscriber.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a7ed8fdf17c566f3f9ddba38209fb769/href">https://medium.com/media/a7ed8fdf17c566f3f9ddba38209fb769/href</a></iframe><h3>The Future of RSocket Flowable</h3><p>In a previous article <a href="https://gist.github.com/the-state-of-rsocket-in-javascript">The State of RSocket in JavaScript</a>, we reviewed how the future of rsocket-js may be uncertain, and with a maintainer of rsocket-js stating that RSocket Flowable may be replaced in the future by a <a href="https://github.com/rsocket/rsocket-js/issues/45#issuecomment-522035252">new project</a>, I feel the same way about RSocket Flowable. However, the GitHub repo for the proposed replacement has not received meaningful contributions for over 16 months, so it is hard to say if this will occur. It is, of course, possible that the project could be in-development behind the scenes as a closed source project to be released as OSS in the future.</p><h3>Final Thoughts</h3><p>Advancements such as RSocket support the continued adoption of observable patterns. RSocket models a stream of messages moving fluently through a system, with each leveraging a ReactiveX, or a React Streams implementation. Reactive Streams, and ReactiveX (implemented as RxJS in JavaScript), have grown on me after discovering RSocket, and I believe we will continue to see growth and adoption of these patterns over the next couple of years. In the Java ecosystem, it is already clear that Reactive Streams has become more prevalent through the popular Project Reactor.</p><p>I recommend diving deeper into these concepts if building highly scalable reactive microservices and real-time interfaces intrigues you.</p><p><em>Originally published at </em><a href="https://viglucci.io/reactive-streams-in-javascript-with-rsocket-flowable">https://viglucci.io/reactive-streams-in-javascript-with-rsocket-flowable</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=683097ff91eb" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/reactive-streams-in-javascript-with-rsocket-flowable-683097ff91eb">Reactive Streams in JavaScript with RSocket Flowable</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The State of RSocket in JavaScript]]></title>
            <link>https://medium.com/swlh/the-state-of-rsocket-in-javascript-05-2020-75a54575319?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/75a54575319</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[rsocket]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Fri, 29 May 2020 15:54:10 GMT</pubDate>
            <atom:updated>2020-05-31T01:45:00.257Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*xM0OR3U8vACWGCmIAElJkQ.png" /></figure><p>RSocket is an exciting new advancement in the application protocol space with decent adoption and support in the Java ecosystem, largely due to contributions to the Java implementation from companies such as <a href="https://pivotal.io/">Pivotal</a>, and decent support for RSocket in the popular <a href="https://spring.io/">Spring</a> framework. With respect to JavaScript, RSocket hasn’t quite picked up the same level of popularity, adoption, or investment as other protocols, such as <a href="https://graphql.org/">GraphQL</a>.</p><h3>Stiff Competition</h3><p>Let’s compare RSocket’s search popularity with GraphQL’s to help gauge the popularity of each protocol.</p><p>In the below graph, we see that RSocket’s search popularity only started picking up steam in late 2018.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*7L4-OX7hbcF2Rpd0.png" /><figcaption>Source: <a href="https://trends.google.com/trends/explore?date=2015-01-01%202020-03-15&amp;q=rsocket">Google Trends</a></figcaption></figure><p>In contrast, GraphQL has experienced a much steeper increase in search popularity, starting in 2016.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ienb0GxZbQwfoEUo.png" /><figcaption>Source: <a href="https://trends.google.com/trends/explore?date=2015-01-01%202020-03-15&amp;q=graphql">Google Trends</a></figcaption></figure><h3>Drawing Parallels</h3><p>If we draw a parallel between search popularity and industry adoption, RSocket has yet to experience the same search popularity growth as GraphQL, signifying that it hasn’t achieved the same level of adoption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*2Y7IbAEwwQCFFAep.png" /><figcaption>Source: <a href="https://trends.google.com/trends/explore?date=2015-01-01%202020-03-15&amp;q=rsocket,graphql">Google Trends</a></figcaption></figure><p>GraphQL in red. RSocket in blue.</p><h3>Popularity and Adoption</h3><p>One can easily contribute the popularity of GraphQL to its conception at Facebook and Facebook’s opensource contributions having high visibility in the JavaScript space. Additionally, the investment into the GraphQL ecosystem from startups such as <a href="https://www.apollographql.com/">Apollo GraphQL</a> has paid dividends into popularizing GraphQL. If RSocket were to gain popularity with large enterprise companies, as well as an engaged audience of JavaScript developers, I believe it could help RSocket experience similar adoption.</p><p>In JavaScript, most developers have become accustomed to leveraging open source packages to solve a wide range of common problems, and it’s never been a better time to avoid reinventing the wheel. However, being that there is only a single reference implementation of RSocket and no well-established supporting libraries if you expect to be able to npm install your way to victory, you&#39;re going to have a bad time with RSocket.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/0*alri9XOcDTNv42Dz.jpg" /></figure><h3>Support for RSocket in JavaScript</h3><p>There exists enough library support to build <em>something</em> with RSocket &amp; JavaScript, however, when it comes to running an application in production, and you start considering monitoring, telemetry, and other needs, your mileage may vary.</p><h3>rsocket-js</h3><p><a href="https://github.com/rsocket/rsocket-js">rsocket-js</a> is the primary reference implementation of RSocket for JavaScript. The library provides the low-level base implementations for several <a href="https://github.com/rsocket/rsocket/blob/master/Protocol.md#transport-protocol">transports</a>, as well as a <a href="https://github.com/rsocket/rsocket/blob/master/Protocol.md#flow-control-reactive-streams">Reactive Streams</a> implementation.</p><p>When building an application, developers will find it is much more practical to consume an abstraction library, such as <a href="https://github.com/rsocket/rsocket-rpc-js">rsokcet-rpc-js</a>, rather than consume rsocket-js directly. However, library authors would likely spend a majority of their time interfacing with rsocket-js directly.</p><p>At first glance, it can be difficult to determine the primary maintainers of the rsocket-js. The contributions as of late have primarily been from engineers who do not appear to be associated with Facebook, however, several of the licenses in the repository reference Facebook, and new contributors to the project are expected to accept the Facebook OSS agreement. Based on this, it appears that Facebook may not be taking a leading role in the libraries continued development, even if they did bootstrap and get the library off the ground initially. It is also important to note that the project has received varying levels of contribution from engineers at companies such as Pivotal and <a href="https://www.netifi.com/">Netifi</a>, as well as contributors from the open-source community.</p><p>The Java implementation of RSocket for Java ( <a href="https://github.com/rsocket/rsocket-java">rsocket-java</a>) has received heavy and continued contributions from engineers at established well-known companies, such as Netflix and Pivotal. This investment by leaders in the Java OSS space provides consumers of rsocket-java with a certain level of confidence that the project has a long life ahead of it, and as such, could feel more comfortable betting their project, and possibly their business of the technology. In contrast, it is uncertain if rsocket-js has a clear set of core maintainers, a defined road map, or is being used by any large companies.</p><h3>rsocket-rpc-js</h3><p>rsocket-rpc-js is an abstraction library that consumes rsocket-js, and in practical terms, is likely the interface that most applications or developers would consume when working with RSocket in JavaScript.</p><blockquote><a href="https://github.com/rsocket/rsocket-rpc-js"><em>rsocket-rpc-js</em></a><em> — “The Standard RPC implementation for RSocket” in JavaScript.</em></blockquote><p>In addition to exposing the reactive streams implementation behind service interfaces that will be familiar to traditional OOP programmers, the library also ties in nicely with RSocket message brokers that facilitate message routing, which can be core to any distributed messaging system.</p><p>RPC style client and server implementations are generally opinionated about the interfaces they expose and how messages are framed/formatted.</p><p>In contrast to a restful API where a consumer requests a User resource by invoking an HTTP GET request to /users/1, where 1 is the user ID, in an RPC API it would more common to invoke a HTTP POST request to /UserService/GetUserById and include in the request body the ID of the user { &quot;userId&quot;: 1 }. rsocket-rpc-js encourages these types of RPC patterns and interfaces. A method following this pattern could have a signature similar to the following: getUserById(Number: id): Single&lt;User&gt;.</p><p><strong>Opinionated APIs and specifications empower tooling</strong> to be built which further standardizes integrations without requiring developers to work around new ideas that present their own unique challenges. For instance, because rsocket-rpc-js and other RSocket RPC implementations follow an established spec, it is possible to generate source code for clients, servers, and message payloads in a number of languages by leveraging common tools and interchange formats such as protoc and protobuf.</p><p>An example of consuming a generated client service produced by protoc when combined with the <a href="https://github.com/rsocket/rsocket-rpc-js/tree/master/rsocket-rpc-protobuf">rsocket-rpc-protobuf protoc plugin</a> would be similar to the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8918aaf4a62624a43b91f864ef46599/href">https://medium.com/media/a8918aaf4a62624a43b91f864ef46599/href</a></iframe><p>In the above example, a service has been implemented that exposes a method that utilizes the “Request Response” flow (review the list of flows on the <a href="https://rsocket.io/docs/Protocol#stream-sequences-and-lifetimes">rsocket.io website</a>), and this helloServiceClient implementation can be generated by protoc when given a protobuf definition such as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6723246cf8fa302593d1deff6a225c9d/href">https://medium.com/media/6723246cf8fa302593d1deff6a225c9d/href</a></iframe><p>In addition to promoting the creation of tooling, a standardized opinionated specification also supports the creation of platform services and solutions, such as <a href="https://www.netifi.com/">netifi</a>, which is a language-agnostic broker for RSocket that aims to solve many of the common service mesh orchestration challenges.</p><h3>rsocket-flowable</h3><p><a href="https://github.com/rsocket/rsocket-js/blob/master/docs/03-flowable-api.md">rsocket-flowable</a> provides an implementation for Reactive Streams in JavaScript, and is deeply ingrained into both rsocket-js and rsocket-rpc-js. Learning the rsocket-flowable API, and what it means to work with Reactive libraries and paradigms is going to be paramount to successfully working with rsocket-js and rsocket-rpc-js.</p><p>If you are familiar with <a href="https://github.com/ReactiveX/rxjs">RxJS</a>, then rsocket-flowable will likely feel familiar to you. If you are not familiar with RxJS, or reactive programming paradigms, then you could experience a somewhat steep learning curve.</p><h3>What to Expect Next</h3><p>While the bulk of ongoing development appears to be centered around the Java and C++ implementations of RSocket, it is my hope that the JavaScript implementation will continue to receive updates and additions to meet the full RSocket spec, but only time will tell.</p><p>If you are passionate about RSocket and a seasoned JavaScript developer, now may be a good time to get involved with the project to leave your mark and assist in its continuity. If contributing to the project is not your cup of tea, then sharing this article and RSocket with your friends, coworkers, and on your social networks would be a great way to increase RSocket’s visibility in the JavaScript community.</p><p>Drop me a comment below, or tweet me on <a href="https://twitter.com/kviglucci">Twitter </a>and let me know if this is the first you are hearing of RSocket, or if you are also closely watching its development, as I am.</p><p><em>Originally published at </em><a href="https://viglucci.io/the-state-of-rsocket-in-javascript">https://viglucci.io/the-state-of-rsocket-in-javascript</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75a54575319" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/the-state-of-rsocket-in-javascript-05-2020-75a54575319">The State of RSocket in JavaScript</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reviewing Messaging in Distributed System Architectures]]></title>
            <link>https://levelup.gitconnected.com/reviewing-messaging-in-distributed-system-architectures-6cf2fd7b8b4e?source=rss-997e6e217b91------2</link>
            <guid isPermaLink="false">https://medium.com/p/6cf2fd7b8b4e</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[websocket]]></category>
            <category><![CDATA[rsocket]]></category>
            <dc:creator><![CDATA[Kevin Viglucci]]></dc:creator>
            <pubDate>Thu, 23 Jan 2020 04:00:46 GMT</pubDate>
            <atom:updated>2021-10-08T04:53:36.522Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Real-time reactive systems are some of my favorite types of systems to build; however, they can be daunting tasks to approach, especially when learning a new programming language or ecosystem along the way. This notion was recently reinforced for me as I set out to build a “simple” real-time client/server application utilizing Javascript/React &amp; Java/Spring, where I quickly learned of several new messaging protocols (Stomp &amp; RSocket).</p><p>Apart from serving as an exercise in <a href="https://meta.wikimedia.org/wiki/Cunningham%27s_Law">Cunningham’s Law</a>, this article aims to expedite the start of your distributed systems research and save you some of the time investment that I have already spent scouring the internet, and <a href="https://twitter.com/vigs072/status/1169987607008296960">screaming into the void on Twitter</a>.</p><p><strong>What should you expect from this article?</strong></p><p>This article serves as a high-level overview of topics related to building real-time/distributed systems using several common patterns, ultimately providing a high-level overview of the RSocket protocol. The goal of this article is not to provide fully working complete code samples or in-depth deep dive into any one topic. Instead, this article aims to guide the reader with understanding the common terminology and concepts so that they can more easily gather a more in-depth understanding as they continue their research elsewhere.</p><h3>What is a distributed system?</h3><p>Distributed systems possess a core characteristic in that a network boundary separates the individual system components. Additionally, in a real-time distributed system, each component reacts to changes as they happen across the system topology, automatically, without existing a requirement for components of the system to keep tabs on or regularly check with other parts of the systems to see if something has changed. Implementing such a system using primarily stateless communication protocols such as HTTP is generally considered bad practice, as it quickly leads to implementations that rely on wasteful polling techniques. However, there exist numerous patterns to overcome the wasteful characteristics of HTTP polling.</p><p>Some common patterns you may see today include Webhooks, Messaging systems (Buses, Brokers, &amp; Queues), and duplex data streams implemented using a persistent connection protocol such as TCP, WebSockets, and less commonly Aeron.</p><h3>Webhooks</h3><p>The implementation of webhooks may be one of the easiest to understand, as well as to implement (as a consumer), as it is no more complicated than adding an HTTP route handler to your application (the consumer) and accepting HTTP requests from event publishers.</p><p>At the core of this pattern is the agreement between publishers and consumers that when a specific event occurs, a publisher agrees to execute an HTTP request against an endpoint implemented on the consumer application, and potentially include with each request some data.</p><p>Once the consumer has received the request from the publisher, the consumer may now take some follow-up action. This follow-up action could include modifying records in a database, executing an HTTP request back to the publisher to consume some additional data or numerous other actions. The sky is the limit. This relationship is, however, known to become problematic in some scenarios. For instance, in systems where publishers publish large volumes of messages, or where the throughput of a publisher is higher than that of its consumers, requests to consumers commonly “back up,” thus causing strain on both the consumer and the publisher as each struggles to free resources.</p><figure><img alt="Diagram showing one publisher publishing to three subscribers" src="https://cdn-images-1.medium.com/max/1024/1*dHfgf6QanecEFngBkAFnpg.png" /></figure><h3>Message Buses, Brokers &amp; Queues</h3><p>Message buses, brokers, and queues are a step up from webhooks in that they avoid some of the scalability issues that can be common when implementing webhooks. With webhooks, there exists a requirement for event publishers to keep track of each consumer who is interested in any given event and to individually notify each consumer when an event occurs. At scale, this characteristic can quickly introduce performance issues as the number of events a publisher publishes and the number of consumers interested in those events increases organically over time.</p><p>To overcome these challenges, a Message Bus, Message Broker, or Message Queue implement similar yet different patterns where they interface with an intermediary component that acts as a “go-between.” This go-between is responsible for ingesting (receiving) events from event publishers and re-publishing those events to each concerned consumer/subscriber, or for receiving requests from consumers asking for any new messages. However, the latter strategy (polling by consumers) is less common and more resource exhaustive. As such, consumers more often are “pushed” messages by the broker as fast as the broker can publish them. This relationship between broker and consumer places the same burden on the consumer as with webhooks, in that they must consume messages at the rate which they are published, or risk the system re-queueing or even dropping messages.</p><p>To accomplish the re-publishing of events and overcome the above issues at scale, systems often involve a high-performance component that supports a persistent connection between publisher and go-between, such as <a href="https://redis.io/">Redis</a>, <a href="https://kafka.apache.org/">Apache Kafka</a>, <a href="https://www.amqp.org/">AMQP</a>/ <a href="https://www.rabbitmq.com/">Rabbit MQ</a>, or a cloud offering such as <a href="https://aws.amazon.com/sqs/">AWS SQS</a>. By employing this go-between, each cog in the wheel (publisher, go-between, and consumer) can all scale independently, as well as reap other benefits, such as avoiding the overhead of establishing a TCP connection for each published message.</p><p>Additional to the benefit of independent scaling of system components, and avoiding the overhead of ephemeral TCP connections, the usage of a Message Bus allows event publishers to be ignorant of the number of, and even who the consumers of events are, and to only concern themselves with communicating with the go-between. Furthermore, consumers/subscribers benefit from this pattern by being ignorant of which applications are publishing events and only need concern themselves with communicating with the bus/broker/queue.</p><figure><img alt="Diagram showing a message bus/broker broadcasting events from publishers to subscribers" src="https://cdn-images-1.medium.com/max/1024/1*7khP972xJj_jOdp5goo6sw.png" /></figure><h3>WebSockets &amp; TCP</h3><p>If you have made it this far into the article, you hopefully recall that in the previous section, we noted that maintaining a persistent connection between a go-between is a common strategy to avoid ephemeral TCP connection overhead. This characteristic of a well designed distributed system also holds for directly establishing persistent connections between publishers and consumers using network protocols such as TCP (for clients/languages which support it directly) or, where TCP is not directly supported, WebSockets.</p><p>However, establishing a direct persistent connection between client/server (either of which can be a consumer or a publisher in this scenario) re-introduces some of the complications overcome by leveraging a Message Bus as a go-between. Most namely, the requirement of the party establishing the connection to have prior knowledge of other parties’ domain names or direct IP addresses, as well as added complexity to scale the overall system as more clients and servers are added to the topology. Regardless, there are many added benefits to leveraging WebSockets or raw TCP as the communication protocol between your system components, with one of the most significant is that data can “flow both ways,” which is unique when compared to Webhooks and Message Buses.</p><figure><img alt="Diagram showing a single WebSocket server which has multiple connected clients" src="https://cdn-images-1.medium.com/max/1024/1*uZe_FckNPX4i4pnjo1RKxg.png" /></figure><p><strong>Duplex Communication</strong></p><p>A characteristic of Webhooks and Message Bus system implementations is generally that data only flows in one direction, from publisher to consumer, which is contrary to a Duplex Communication system that leverages raw TCP or WebSockets, where data flows between components in both directions seamlessly. This bi-directional transfer of data between two connected components over a network boundary, known as “Duplex Communication,” allows for both sides of a connection to react to changes and events occurring in the other with minimal overhead, but with added implementation complexity surrounding the format (protocol) of the messages.</p><p><strong>Message Format</strong></p><p>Similar to how natural spoken languages use a defined list of rules and expectations that both sides of a conversation agree to, so do all network communications. This message format commonly referred to as the “protocol,” dictates to all involved parties how to construct a message, which messages to expect, and possibly in what order.</p><p>A simple implementation of a messaging protocol might define the following parameters and constraints:</p><ul><li>Every 1000 milliseconds, each participant will transmit to the other a “keep-alive” message; otherwise, either participant is free to terminate the connection as they see fit.</li><li>Each message in the exchange must consist solely of UTF8 encoded strings serializable to valid JSON.</li><li>Each message is to include an id and a data property.</li></ul><p>An example message in this protocol may look something like the below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8dd7853a94d1574fd6083504e5975d0/href">https://medium.com/media/b8dd7853a94d1574fd6083504e5975d0/href</a></iframe><p>Given such a protocol, a participant in communications that leverage it would have everything needed to handle incoming messages in an expected and understood manner. In a real-world application, this could manifest as the application invoking the userCreated method on a UserEventHandler class, in which the application has implemented to invoke anytime it receives a message with an id of user_created.</p><p>For the most simple of systems and even some moderately active/complex systems, such a protocol would contain sufficient features to allow for the successful development of the system, with examples of relatively simple (yet still sufficiently complex and featured) protocols such as this including <a href="https://stomp.github.io/">Stomp</a>, and <a href="https://xmpp.org/">XMPP</a>. Extensive usage of protocols similar to these exists in today’s modern applications. Yet, they do not offer mechanisms for overcoming the common pitfall of overloaded consumers; some more recent development in protocols, however, do consider this, such as <a href="http://rsocket.io/">RSocket</a>, through the notion of <a href="https://www.reactivemanifesto.org/glossary#Back-Pressure">back-pressure</a>.</p><h3>The highest of RSocket overviews</h3><p>RSocket is a relatively new addition to the distributed systems landscape, with search term popularity only just starting to increase in the United States since the latter half of 2018 (according to <a href="https://trends.google.com/trends/explore?date=today%205-y&amp;geo=US&amp;q=RSocket">Google Trends</a>). Yet, it offers some exciting concepts which I am personally excited to dig into more.</p><p><strong>Back-pressure</strong></p><p>RSocket supports the concept of <a href="https://www.reactivemanifesto.org/glossary#Back-Pressure">back-pressure</a>, which at its core means that any given component of a system is empowered to control the rate at which messages transmissions occur between itself and other components of the system. This concept allows for a client to communicate to a server that it is prepared to handle N number of messages and that the server should send it no more than N messages without the client requesting additional messages.</p><p><strong>Message types</strong></p><p>The RSocket protocol supports multiple message types, each of which satisfies common request/response patterns utilized in various numbers of systems.</p><p><strong>Fire and Forget</strong> — The client sends a message to the server and does not expect the server to send a response. The client sends the message immediately.</p><p><strong>Request Response</strong> — The client is to send a message to the server and expected the server to respond with precisely one response message. The client does not send the request message until it has also prepared to handle the response.</p><p><strong>Request Stream</strong> — The client sent a request to the server and expected the server to respond with N number of responses. The client does not send the request until it is prepared to handle the responses, and the server does not send the responses until the client has executed subsequent request(s) for N responses.</p><p><strong>Request Channel</strong> — The client and server each prepare themselves to transmit and to receive N number of messages from the other. Neither client nor server transmits messages to the other until the other has signaled they are prepared to handle messages by first requesting N number of messages from the other.</p><p><strong>Multiple Language Implementations</strong></p><p>Although RSocket is a relatively new technology, the protocol can be implemented in any language or runtime, which can utilize either TCP directly or WebSockets. This characteristic of the protocol has allowed for client/server implementations in Java, Javascript, Go, .NET, C++, and Kotlin. The full list of language implementations and the full set of protocol features can be reviewed on the official <a href="http://rsocket.io/">RSocket website</a>.</p><h3>Webhooks, Message Buses, and WebSockets, oh my!</h3><p>We covered much ground reviewing Webhooks, Message Buses, WebSockets, and finally, an overview of RSocket. With any luck, this article has assisted you with learning something new and assisted you with deciding which architecture(s) best fit your application’s use cases and requirements.</p><p>If you found this article helpful, let me know in the comments below, drop me a note on Twitter (link in the bio below), or if you would be so kind, share it on your favorite social media network. If you found this article to be widely inaccurate, or take other issue with any of the content, feel free to send me your favorite disdainful meme on Twitter. Might I suggest a <a href="https://knowyourmeme.com/memes/woman-yelling-at-a-cat">current trend</a>?</p><p><em>Originally published at </em><a href="https://viglucci.io/reviewing-distributed-system-architectures">https://viglucci.io/reviewing-distributed-system-architectures</a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6cf2fd7b8b4e" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/reviewing-messaging-in-distributed-system-architectures-6cf2fd7b8b4e">Reviewing Messaging in Distributed System Architectures</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>