<?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 Peter van Vliet on Medium]]></title>
        <description><![CDATA[Stories by Peter van Vliet on Medium]]></description>
        <link>https://medium.com/@peter_masking?source=rss-ec9f0e30558b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*py2FXnDGvh79Ht1MCxKpYA.png</url>
            <title>Stories by Peter van Vliet on Medium</title>
            <link>https://medium.com/@peter_masking?source=rss-ec9f0e30558b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:53:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@peter_masking/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[From OOP to OOPS: Escaping the One-Paradigm Trap]]></title>
            <link>https://levelup.gitconnected.com/from-oop-to-oops-escaping-the-one-paradigm-trap-948a83d67559?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/948a83d67559</guid>
            <category><![CDATA[programming-paradigms]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[code-quality]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Fri, 14 Nov 2025 19:08:10 GMT</pubDate>
            <atom:updated>2025-11-14T19:08:10.716Z</atom:updated>
            <content:encoded><![CDATA[<h4>Programming paradigms aren’t silver bullets. So, how to pick the right one? You simply don’t.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*lWtHFMkBrOLfp9j5ROzvFg.png" /><figcaption>Image by author</figcaption></figure><p>Most modern languages already support more than one paradigm, and for good reasons. It’s becoming increasingly clear that blending them can lead to better readability and maintainability. But that raises a new challenge: what’s a good blend?</p><p>This article shares the result of my journey towards a blend that works for most of the applications I build. If you’ve read my previous article about <a href="https://medium.com/gitconnected/cut-the-abstractions-software-is-not-a-piece-of-art-0dbe40271a36">limiting the use of abstractions</a>, then you can see this as a deep dive into picking the right paradigm for the job.</p><p>To make this practical, I’ve developed a simple rule-based framework. As a case study, we’ll refactor an over-engineered Object-Oriented API into a leaner, more comprehensible design.</p><h3>Paradigms and Languages</h3><p>The framework focuses on the paradigms most commonly supported by modern languages:</p><ol><li><strong>Imperative </strong>— code as a sequence of statements executed in order, often with side effects</li><li><strong>Procedural </strong>— organizing imperative code into reusable procedures or functions to structure programs</li><li><strong>Object-Oriented</strong> — modeling data and behavior using objects and classes, emphasizing encapsulation, inheritance, and polymorphism</li><li><strong>Functional</strong> — emphasizing pure functions, immutable data, and higher-order functions to reduce side effects</li></ol><p>Not every language fully supports all of these paradigms at the top level allowing them to be accessed from the global scope. The framework works best in languages that do, which narrows our choices to:</p><ul><li>JavaScript / TypeScript</li><li>PHP</li><li>Python</li><li>Ruby</li></ul><p>It can also be applied in languages that lack top-level imperative support, though with some caveats I’ll explain later:</p><ul><li>Go</li><li>Kotlin</li><li>Scala</li></ul><p>Coming from a Java background, it’s a little disappointing to see it doesn’t make the cut, but I’m hopeful for future developments.</p><h3>Case Study Application</h3><p>Here’s the oops of the story: a simple, commonly patterned Object-Oriented API.</p><p>It’s a minimal cats API built with the usual layers: controller, service, and repository. In TypeScript, using NestJS, a simplified version looks like this:</p><pre>@Controller(&#39;cats&#39;)<br>export class CatsController<br>{<br>  constructor(private catsService: CatsService) {}<br><br>  @Get()<br>  getAllNames(): string[]<br>  {<br>    return catsService.getAllNames();<br>  }<br>}<br><br>@Injectable()<br>export class CatsService<br>{<br>  constructor(private catsRepository: CatsRepository) {}<br><br>  getAllNames(): string[]<br>  {<br>    const cats = this.catsRepository.findAll();<br>    return cats.map(cat =&gt; cat.name);<br>  }<br>}<br><br>@Injectable()<br>export class CatsRepository<br>{<br>  constructor(private database: Database) {}<br><br>  findAll(): Cat[]<br>  {<br>    // Query the database and map the results<br>  }<br>}</pre><p>Each class has a decorated role and gets a single instance through dependency injection. You know, the works. Any experienced backend developer will recognize this. And that’s exactly the problem.</p><p>Reading and maintaining this code requires knowledge and experience with:</p><ul><li><strong>Layered architecture </strong>— controller, service, and repository</li><li><strong>OO design</strong> — patterns and principles</li><li><strong>Meta-programming</strong> — decorators, annotations, attributes</li></ul><p>From my time as a software engineering lecturer, I know these aren’t the simplest concepts. And from my time as a developer and architect (still going), I’ve learned that these ideas often add more complexity than value, and that much of this can be done with far simpler constructs.</p><h3>The framework</h3><p>First, I’ll explain the rules and use cases for each paradigm. Then I’ll blend them in our refactored case study application.</p><h4>Imperative</h4><p>The starting point for everything, unless there’s a good reason not to. Perfect for simple, single-focused, and small use cases such as:</p><ul><li>Bootstrapping an application</li><li>Configuration of resources</li><li>Migration of data</li></ul><p>In languages that don’t support imperative top-level, a procedure / function can be used as a wrapper for the implementation. In languages that don’t support procedural top-level, press the abort button.</p><p>In my time as a lecturer I taught Java to hundreds of students. Of course, the first application they needed to write was “Hello World”. But before I could explain the actual printing statement, I needed to introduce the concept of classes, and even worse: public static void main(String[] args).</p><p>While looking at a classroom filled with students looking like deer in the headlight, I went with “just repeat this pattern”. For most students it took over a year before they somewhat understood what it all meant.</p><h4>Procedural</h4><p>The center of gravity. Perfect for implementing all application, business, and persistence logic (that is, the resource, service, and repository layers).</p><p>Procedures come in two flavors:</p><ol><li><strong>Orchestrator</strong> — coordinates processes or workflows</li><li><strong>Performer</strong> — executes a specific task</li></ol><p>Each procedure should have a single, clear responsibility. This approach enforces separation of concerns and maximizes reusability.</p><p>In our company, we internally refer to this as the <strong>Manager / Expert Pattern</strong>, since it mirrors how those roles work in an organization.</p><h4>Object-Oriented</h4><p>The complexity dealer. Perfect for situations where internal state and behavior need to be combined, such as:</p><ul><li>UI components</li><li>Game entities</li><li>Large or complex data structures</li></ul><p>Each class should have a single, clear responsibility, and implement only logic directly related to its own state, or the state of its children.</p><p>Design patterns are generally frowned upon, but allowed when they solve a clear problem without introducing unnecessary complexity. Static classes and singletons are absolute no-nos.</p><h4>Functional</h4><p>The workhorse. Perfect for helper functions that provide scalable, predictable transformations, such as:</p><ul><li><strong>Data processing</strong> — transforming collections with functions like filter, map, and reduce</li><li><strong>Calculations</strong> — pure functions free of side effects</li><li><strong>Concurrency</strong> — easily parallelizable due to immutability</li></ul><p>Primarily used within performer procedures or classes, either as lambdas or named functions.</p><h4>Refactored application</h4><p>Using the framework, the application can be refactored. Not by fully rewriting everything, but by reusing the logic. Admittedly, that’s not much in this case.</p><p>NestJS doesn’t fit the framework, so I’m switching to Express. It lets you map procedures straight to API endpoints, which is all we need here. Other languages have similar minimal frameworks.</p><p>The refactored application now looks like this:</p><pre>const app = express();<br>app.get(&#39;/cats&#39;, (req, res) =&gt; { res.json(getAllCatNames()); } );<br>app.listen(3000);<br><br>function getAllCatNames(): string[] // Orchestrator<br>{<br>  const cats = findAllCats();<br>  return extractCatNames(cats);<br>}<br><br>function extractCatNames(cats: Cat[]): string[] // Performer<br>{<br>  return cats.map(cat =&gt; cat.name);<br>}<br><br>function findAllCats(): Cat[] // Performer<br>{<br>  // Query the database and map the results<br>}<br><br>class Cat // Real-world concept<br>{<br>  constructor(public name: string, private energy: int) {}<br>  walk(distance: int) { /* update energy */ } <br>  sleep(hours: int) { /* update energy */ }<br>  eat(amount: int) { /* update energy */ }<br>}</pre><p>This code does exactly the same, while still being more complete and in fewer lines.</p><p>Let’s break it down:</p><ul><li>The first three lines <strong>imperatively</strong> bootstrap the app.</li><li>The <strong>procedures</strong> below handle the actual logic, using <strong>functional</strong> helpers for transformations.</li><li>And at the end sits the Cat <strong>class</strong>, representing a real-world concept.</li></ul><p>Nothing mysterious: just clear, reusable logic that’s friendly to juniors and forgiving for future you.</p><h3>Final thoughts</h3><p>I’ve deliberately kept the example application small and simple. Not because the framework doesn’t fit large-scale applications, but to keep the focus on the essentials: rules and reasoning. For a large-scale example, check out this <a href="https://github.com/MaskingTechnology/comify">open-source comic-based social-media platform</a> I’m working on.</p><p>As with anything, this framework is not a silver bullet. It works best for process-driven, business-oriented applications, which make up the majority of real-world software. I’m also working on an <a href="https://github.com/MaskingTechnology/jitar">open-source distributed runtime</a> that’s fully object-oriented, layered with abstractions, and glued together with patterns and principles. And that’s okay, it fits the context.</p><p>I’ve been on this road for quite some time, and it’s encouraging to see procedural programming gaining recognition for process-driven applications. I predict that more languages will eventually support top-level procedural programming. But maybe I’m just a bit naive.</p><p>At the very least, I hope I’ve given you some food for thought, and perhaps a little push toward building more readable and maintainable applications.</p><p>I’m curious to hear your thoughts! Leave a comment. And don’t forget to clap if you liked this.</p><p>I’m planning a follow-up on how to apply this framework to real-world, large-scale applications, showing how to incorporate more of the guidelines from my previous <a href="https://medium.com/gitconnected/cut-the-abstractions-software-is-not-a-piece-of-art-0dbe40271a36">article on abstractions</a>.</p><p>Thanks for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=948a83d67559" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/from-oop-to-oops-escaping-the-one-paradigm-trap-948a83d67559">From OOP to OOPS: Escaping the One-Paradigm Trap</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[Cut The Abstractions, Software is Not a Piece of Art]]></title>
            <link>https://levelup.gitconnected.com/cut-the-abstractions-software-is-not-a-piece-of-art-0dbe40271a36?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/0dbe40271a36</guid>
            <category><![CDATA[software-design]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Wed, 27 Aug 2025 14:36:30 GMT</pubDate>
            <atom:updated>2025-08-27T14:36:30.911Z</atom:updated>
            <content:encoded><![CDATA[<h4>A pragmatic guide to the true art of building scalable and maintainable systems.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*15AF8eLM9HNikQdiNonU2Q.png" /></figure><p>We need abstractions to build scalable and maintainable systems. But boy, can they make a mess. Their pull is hard, but restraint pays off.</p><p>This article is a concrete guide to abstractions: from definitions to directly applicable guidelines.</p><p>By the end, you’ll better understand the value of abstractions and be able to make more informed decisions about when (and whether) to use them.</p><p>This article is designed for readers of all experience levels. It starts with a short primer to get everyone on the same page before diving into the cutting guidelines.</p><p>Table of Contents:</p><ul><li><strong>Complexity</strong> — types and dimensions</li><li><strong>Abstractions</strong> — values, risks and challenges</li><li><strong>Implementations</strong> — levels, mechanisms and design patterns</li><li><strong>Cuts</strong> — practical guidelines with examples</li></ul><p>I recommend reading all sections, but feel free to scan or skip parts you’re already comfortable with.</p><h3>Complexity</h3><p>In software design, complexity refers to the difficulty of understanding, building, maintaining, and evolving a system. It arises from the structure, interactions, and behavior of the system’s components.</p><p>There are two major types of complexity often discussed:</p><ol><li><strong>Essential</strong> — inherent domain complexity (e.g., flight control, financial trading).</li><li><strong>Accidental</strong> — avoidable design complexity (e.g., poor abstractions, unclear code).</li></ol><p>Essential complexity must be accepted and managed. Accidental complexity, however, is entirely within our control.</p><p>Complexity can be assessed across multiple dimensions:</p><ol><li><strong>Structural</strong> — the number of components and how they are connected (dependencies, coupling, cohesion).</li><li><strong>Cognitive</strong> — how difficult it is for humans to read, understand, and reason about the code.</li><li><strong>Algorithmic</strong> — performance characteristics such as time and space complexity.</li><li><strong>Organizational</strong> — the impact of team structure, communication, and processes on the system.</li></ol><p>The more complex a system is, the harder it becomes for developers (and AI) to reason about it correctly.</p><p>The remedy? Keep it simple!</p><h3>Abstractions</h3><p>One of the primary ways to reduce system complexity is through the use of abstractions. In essence, abstractions hide unnecessary implementation details and expose only the essential features needed for a particular purpose.</p><p>Without abstractions, building complex, scalable, and adaptable systems would be impractical, if not impossible. But when abstractions become a distraction, their value is lost. Instead of reducing complexity, they add it.</p><p>The challenge is finding the right abstractions in the right balance:</p><ul><li><strong>Too little</strong> abstraction hurts maintainability.</li><li><strong>Too much</strong> abstraction hurts understandability.</li><li><strong>Wrong</strong> abstractions hurt both.</li></ul><p>While there is no golden rule, there is a widely accepted guideline:</p><blockquote>Avoid abstractions until they are truly needed.</blockquote><p>In practice, this is often easier said than done, even for experienced developers.</p><p>Using abstractions not only feels professional, but also provides a sense of protection against future changes. This can make them tempting to introduce too early, often resulting in excessive or misguided abstractions.</p><p>Discipline is the only savior: be strong!</p><h3>Implementations</h3><p>Abstractions are applied through their implementations, which can occur at multiple levels.</p><p>From a system perspective, there are four core levels to consider:</p><ol><li><strong>Architecture</strong> — system organization (e.g., microservices, layers)</li><li><strong>Structure</strong> — component organization (e.g., modules, packages, namespaces)</li><li><strong>Communication</strong> — interaction coordination between components (e.g., orchestration, choreography)</li><li><strong>Component</strong> — internal behavior and structure (e.g., classes, procedures)</li></ol><p>While the first three levels are the most fundamental, the fourth level contains the greatest density of abstractions. The ways in which these abstractions are implemented can vary, often depending on the programming paradigm.</p><p>In a paradigm-agnostic sense, three mechanisms are often considered core:</p><ol><li><strong>Generalization</strong> — defining shared characteristics in an abstract form that can be specialized by concrete implementations.</li><li><strong>Polymorphism</strong> — enabling a single operation or interface to support multiple interchangeable implementations.</li><li><strong>Encapsulation</strong> — exposing a simplified interface while hiding internal details.</li></ol><p>These are most widely associated with the object-oriented paradigm, but they are also present in other paradigms such as procedural and functional programming.</p><p>Together, they enable creating simple-to-use, interchangeable, and reusable components. But only if they’re properly defined and named. Otherwise, you’re at risk of ending up with a brittle system that no one understands.</p><p>From these mechanisms, many <a href="https://refactoring.guru/design-patterns">design patterns</a> have emerged. Their value lies in providing solutions to common problems. They typically fall into one of the following categories:</p><ul><li><strong>Creational</strong> — patterns for object creation (e.g., Factory, Builder)</li><li><strong>Structural</strong> — patterns for component composition (e.g., Decorator, Facade)</li><li><strong>Behavioral</strong> — patterns for component collaboration (e.g., State, Strategy)</li></ul><p>Once you’ve mastered these, it’s hard not to feel invincible. Until you start applying them everywhere and end up creating a monster more invincible than you are.</p><p>Heard that from a friend…</p><h3>Cuts</h3><p>Now for the part you’ve probably been waiting for.</p><p>The key to cutting abstractions is to avoid them when possible, or to replace them with simpler alternatives.</p><p>For each abstraction level, two practical guidelines are provided. This isn’t an exhaustive list, but a selection of common approaches that apply to most modern systems.</p><p>Keep in mind: context is everything. None of these guidelines apply in every situation.</p><h4>Architecture</h4><p>At this level, decisions are made about the overall system organization.</p><p>These choices are fundamental and therefore hardest to change, yet they must be made earliest. This combination often causes upfront overdesign, introducing abstractions too early. Here, discipline to keep it simple matters most.</p><p><strong>Guideline #1 — Favor monolith over microservices</strong></p><p>Most systems don’t need microservices, and that’s a good thing. By raising the level of abstraction through indirection and network-based calls, they make system behavior more implicit and harder to follow.</p><p>Monoliths avoid this extra layer of abstraction, making them the better choice when there are no clear needs for services, such as independent deployability or fault tolerance.</p><p>For large systems, monoliths can still be a suitable choice. By breaking the system into independent modules enables encapsulation and distributed ownership. This is known as a modular monolith.</p><p>A natural growth path often looks like this: <em>monolith → modular monolith → microservices</em>.</p><p><strong>Guideline #2 — Use fewer layers</strong></p><p>Systems are naturally built with layers of responsibility, which is generally beneficial. However, too many layers (= abstractions) introduce indirection and often result in “hatch” functions that do little more than pass calls along.</p><p>Using fewer layers avoids these accidental complexities. A classic three-layer architecture is usually sufficient: <em>presentation → business logic → persistence</em>.</p><p>Additional layers should be introduced only when a concern (e.g. security, integration, caching) begins to obscure the responsibilities of the existing layers.</p><p>Remember: it’s easier to add layers than to remove them.</p><h4>Structure</h4><p>At this level, the organized system is decomposed into modules, packages, and similar constructs.</p><p>To make a system effectively maintainable, its structure needs to be navigable, like a well-drawn map.</p><p><strong>Guideline #1 — Encapsulate groupings</strong></p><p>Modules, packages, and similar constructs group coherent functionality. This is beneficial for the navigability of the system. But only when they have clear, explicit boundaries.</p><p>Clear boundaries define what is internal versus what is exposed, reinforcing the module’s encapsulation. Without it, their abstraction value is lost, leading to unnecessary coupling and added structural and cognitive complexity.</p><p>It’s generally better to organize by domain concept (e.g., users, products) rather than by technical roles (e.g., entities, controllers). This keeps related functionality together, rather than scattering it across boundaries.</p><p>In addition to reducing complexity, it also makes the system easier to scale.</p><p><strong>Guideline #2 — Keep a flat structure</strong></p><p>As the number of modules or packages grows, it becomes harder to oversee the system. Grouping these constructs into higher-level collections can improve organization and navigability.</p><p>While this adds a valuable layer of abstraction, it should be done carefully. Too many nested layers can quickly become counterproductive.</p><p>Keeping no more than four nesting levels is generally manageable for cognitive complexity. Five or more levels are typically considered high complexity and harder to reason about.</p><p>Feature-based vertical sliced decomposition is considered a modern best practice. For large applications, a typical structure is: <em>business capability → subdomain → feature</em>. Each feature contains the implemented components.</p><p>Smaller applications can skip levels, using <em>subdomain → feature</em>, or, in very small cases, just <em>feature</em>.</p><h4>Communication</h4><p>At this level, the focus is on how components interact and coordinate with each other.</p><p>Traceability is critical for building maintainable systems. Without it, interactions become implicit, making the system harder to understand, extend, and debug.</p><p><strong>Guideline #1 — Favor orchestration over choreography</strong></p><p>Orchestration centralizes interactions by directing the sequence of component actions, making the process explicit and predictable.</p><p>Choreography, by contrast, decentralizes interactions, allowing components to react autonomously to events. This introduces an additional layer of abstraction, making the process more flexible and loosely coupled, but also less explicit and potentially harder to predict.</p><p>While best practices vary across domains (e.g., business, entertainment, science), it is generally advisable to use orchestration only where it provides clear value.</p><p>In business domains, this typically means <em>orchestrating core workflows</em> that define the business process, while relying on <em>choreography for side effects</em> (e.g., notifications, metrics).</p><p><strong>Guideline #2 — Favor synchronous over asynchronous</strong></p><p>Synchronous communication waits for a response from each component call before proceeding, while asynchronous communication continues immediately without waiting.</p><p>From a traceability standpoint, synchronous communication is the clear winner. Like orchestration, it makes the process explicit and predictable.</p><p>Both orchestration and choreography can use either synchronous or asynchronous styles, but it’s best to align them to avoid confusion and extra complexity: <em>orchestration works best with synchronous</em> communication, <em>choreography with asynchronous</em>.</p><p>Mixing styles can increase complexity, but may be beneficial in specific cases: orchestration can use asynchronous calls to optimize performance or responsiveness, while choreography can fall back to synchronous calls when coordination is unavoidable.</p><h4>Component</h4><p>At this final level, the system is composed of the functional building blocks that implement the behavior defined by higher-level abstractions.</p><p>Low coupling and high cohesion are key to reducing their overall complexity. Abstraction mechanisms can support them, but only when used correctly. This is where the most delicate balancing act takes place.</p><p><strong>Guideline #1 — Favor procedural over object-orientation</strong></p><p>The object-oriented paradigm is dominant, but that doesn’t mean it’s always the best choice. Each paradigm comes with its own abstraction style, suited for specific contexts.</p><p>Object orientation encapsulates state and behavior together. This works well for stateful domains where behavior is tightly coupled to data (e.g., a User object with a login() method). But in stateless or flow-oriented contexts (e.g., utilities, workflows), it often introduces unnecessary abstraction.</p><p>In these cases, a simpler procedural approach is more explicit and reduces accidental complexity by separating state from behavior and avoiding the overhead of classes and objects.</p><p>In practice, the two styles complement each other: <em>procedural style for stateless</em> workflows (orchestration) and tasks (e.g. querying, transformations), and <em>object orientation for stateful</em> business models.</p><p><strong>Guideline #2 — Be aware of hidden abstractions</strong></p><p>Many more abstraction choices are available at this level. Some obvious, others hidden. Being aware of them helps prevent unnecessary complexity.</p><p>Things to favor:</p><ul><li><strong>Explicit control flow (if/else/switch) over behavioral patterns</strong> → keeps logic clear and predictable.</li><li><strong>Concrete implementations over creational patterns</strong> → simplifies understanding and debugging.</li><li><strong>Manual dependency injection over automation</strong> → makes relationships explicit and avoids hidden coupling.</li><li><strong>Language capabilities over frameworks and libraries</strong> → standardizes implementations and reduces external abstractions.</li><li><strong>Code generation or compile-time mechanisms over runtime abstractions</strong> → resolves abstractions early, simplifying runtime behavior.</li></ul><p>Things to avoid:</p><ul><li><strong>Inline or small local helper functions</strong> → don’t abstract unless reused meaningfully.</li><li><strong>Overly abstract interfaces</strong> → interfaces that aren’t reused or don’t simplify testing add indirection without value.</li><li><strong>Excessive inheritance hierarchies</strong> → deep or broad class structures increase cognitive load.</li><li><strong>Overuse of generics or templates</strong> → flexible types can hide behavior, making it harder to understand.</li><li><strong>Reflection or dynamic dispatch</strong> → obscures what’s actually happening.</li></ul><p>Understanding these options and their trade-offs allows you to spot abstractions early, weigh their costs, and avoid surprises that increase complexity.</p><h3>Conclusions</h3><p>Where there’s abstraction, there’s complexity.</p><p>The art of building scalable and maintainable systems lies in avoiding unnecessary abstractions within the context at hand, and in introducing the right ones as the system evolves.</p><p>This requires knowledge of options, guidelines and trade-offs, and discipline to use them in the fight for simplicity.</p><p>While the knowledge can be learned from books, talks, and articles, the discipline must come from you.</p><p>Keep in mind that, in the end, it’s all worth it.</p><p>Thanks for reading. If you found this article valuable, don’t forget to clap. I’m always open to questions and feedback, so don’t be shy.</p><p>If you’re interested in exploring systems that showcase different levels of abstractions, here are two open-source projects I’m working on:</p><ol><li><strong>A comic-based social media platform</strong> — follows almost all best practices from this article: monolith-first, feature-oriented, and procedural. [<a href="https://github.com/MaskingTechnology/comify/tree/main/src/domain">GitHub</a>]</li><li><strong>A distributed JavaScript runtime</strong> — intentionally built with many abstractions: fully OO, composition-based, and rich in design patterns. [<a href="https://github.com/MaskingTechnology/jitar/tree/main/packages">GitHub</a>]</li></ol><p>Take care!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0dbe40271a36" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/cut-the-abstractions-software-is-not-a-piece-of-art-0dbe40271a36">Cut The Abstractions, Software is Not a Piece of Art</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 Anatomy of a Distributed JavaScript Runtime | Part V — Consolidation and conclusions]]></title>
            <link>https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e84b04148f54</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Tue, 12 Aug 2025 08:41:44 GMT</pubDate>
            <atom:updated>2025-08-12T08:41:44.763Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Anatomy of a Distributed JavaScript Runtime | Part V — Consolidation and conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jLXU9IJJdsiQSiKPGKXJjg.png" /><figcaption>The scalpel is playful, the runtime filled with joy (image by author)</figcaption></figure><p>In this article series, I’ll share how monolithic JavaScript (and TypeScript) applications can be split into distributed (micro)services with just configuration. We’ll explore the technical mechanics of this transformation and the principles for designing applications that embrace this duality.</p><p>The runtime we’ll be dissecting is Jitar. It’s fully open source, and you’ll find a link to the GitHub repository at the bottom of this article.</p><p>The series is divided into the following parts:</p><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe">Part I — Motivation and goals</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778">Part II — Splitting applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc">Part III — Running applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f">Part IV — Distributing applications</a><br><strong>Part V — Consolidation and conclusions</strong></p><p>If you’re only interested in the technical aspects, you can skip the first and last part. However, I recommend reading at least the first part to better understand the decisions made in the later sections.</p><h3>Part V — Consolidation and conclusions</h3><p>In the previous part, we’ve taken the final technical step of the runtime by exploring the mechanics behind the distribution. In this final part, I’ll draw conclusions and share some final words.</p><p>Before we do that, let’s first recall the most important pieces from the previous parts and put them together to see the complete puzzle.</p><h3>Recap and consolidation</h3><p>Our primary goal is to reduce modern architectural uncertainty caused by microservices fatigue. We do so by decoupling the development model from the deployment model.</p><p>To make this concept a reality, we developed a runtime that enables full-stack modular monolithic applications to be distributed across servers and web browsers.</p><p>In essence, the runtime has two key tasks:</p><ol><li><strong>Build</strong> — Split and rewrite the application into distributable bundles.</li><li><strong>Run</strong> — Load and execute the bundles, either distributed or standalone;</li></ol><p>The first task is performed through configurable segmentation of the application on a per-module basis, as described in detail in part two of this series.</p><p>The second task is handled by a composable set of services that automate communication between the bundles, as covered in part three and four of this series.</p><p>Of course, the application bundles need to be built before the application can run.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*SqMMRo0rMQ9W0oY6" /></figure><p>The build step only needs to be executed when the application has changed, whereas the run step can be executed at any time as needed.</p><p>Now, let’s make things a bit more interesting by examining the same process from both a logical and a physical viewpoint.</p><h4>Logical view</h4><p>The runtime addresses both the development and deployment aspects of an application, so I want to place equal emphasis on both here.</p><p>The build step clearly belongs to development, while the run step typically falls under deployment. However, once we consider their required resources, the distinction isn’t so black and white.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/0*x5UK_MBTwdBhuH36" /></figure><p>During development, the focus is on building modules, while services come into play during deployment. Segments are what introduce the grey area in this picture.</p><p>Although defining segments is clearly part of the deployment strategy, segments are essential for building the distributable bundles. As a result, they need to be available during development and effectively sit between development and deployment.</p><p><strong>T</strong>his does not conflict with the runtime’s primary feature of separating the development and deployment <strong>models</strong>. Both models can still maintain their own independent decomposition structures. For example, the development model might follow a business capability decomposition, while the deployment model could be based on performance or security considerations.</p><p>Suppose we only want to add security layers to our example application by placing firewalls between them. In that case, the models might look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*vd1sWBL6J_XlrJgc" /></figure><p>At deployment, separate instances of the worker service can be started with firewalls between them to control communication. During development, the standalone mode can be used to bypass the more complex production setup.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*CDQVMqyh7SJTxokl" /></figure><p>Even without looking too closely, I think you can spot the difference between the two.</p><h4>Physical view</h4><p>At their core, applications are all about files and folders. The runtime needs to handle not only the source files of the modules, but also the segment and service configuration files.</p><p>A minimal project structure that we use looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*-PvY8eTeVXIe7lqt" /></figure><p>In this view, the resources are mapped to their corresponding project folders. Additionally, there’s a dist folder, which contains the built distributable bundles used at runtime. It’s intentionally greyed out because it’s regenerated with each build and isn’t considered an official part of the project.</p><p>Conceptually, the src folder represents the development model, whereas the dist folder corresponds to the deployment model.</p><p>For our example application — using the deployment model from the previous section — the folder structure for both look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*SPXcKxbb8kTGYlPI" /></figure><p>In this case, the module files would be segmented as follows:</p><ul><li>reporting/formatMonthReport.js → presentation</li><li>reporting/getMonthReport.js → business</li><li>sales/getMonthData.js → persistence</li></ul><p>For those paying attention: yes, I intentionally left out the utils/createPdf.js file to keep the focus clear.</p><p>I believe both views provide a clear picture of how the runtime fulfills its primary goal. But what about the other goals?</p><h3>Conclusions</h3><p>In terms of design goals, we’re quite happy with the overall result. We’ve created a solution that operates at the runtime level, supports full-stack applications that are easier to develop and deploy, integrates with other systems, and is extensible.</p><p>While dynamic split-offs and reintegrations are still missing to fully realize our end vision, we’re confident we can make them work. We’ve already defined how this should function and even have a working prototype.</p><p>At the same time, the design goals aim to shift all distribution concerns to the runtime level. Our utopian vision is to build any type of application without having to think about distribution at all. But in reality, there are still rules of engagement that need to be followed.</p><p>I’ve touched on most of these in the previous parts, but they’re important enough to deserve a second, closer look.</p><h4>Programming paradigms</h4><p>I think it’s clear that the runtime primarily embraces the procedural paradigm. For us, this is a great fit from both the application and runtime perspectives.</p><p>Most of the applications we’ve built revolve around process automation. These processes are typically broken down into workflows that orchestrate a series of tasks. This approach aligns perfectly with the procedural model. I believe the example used throughout this series illustrates that quite well.</p><pre>/* imports */<br><br>export default async function getMonthReport(year, month)<br>{<br>  const data = await getMonthData(year, month);<br>  const report = await formatMonthReport(data);<br><br>  return createPDF(report);<br>}</pre><p>Procedures (or functions, in JavaScript) are stateless by nature and easy to translate into remote calls. That makes them an ideal foundation for building distributable applications.</p><p>As explained in the previous part, we still see value in using (custom) classes to share state between functions. For example, the parameters of the getMonthReport function could be grouped into an immutable model class.</p><pre>export default class MonthSelection<br>{<br>  #year;<br>  #month;<br><br>  constructor(year, month)<br>  {<br>    this.#year = year;<br>    this.#month = month;<br>  }<br><br>  get year() { return this.#year; }<br><br>  get month() { return this.#month; }<br>}</pre><p>And used by our function.</p><pre>/* imports */<br><br>export default async function getMonthReport(monthSelection)<br>{<br>  const data = await getMonthData(monthSelection);<br>  const report = await formatMonthReport(data);<br><br>  return createPDF(report);<br>}</pre><p>Classes can also be useful for building utilities that support functions. A utility can maintain state, as long as its scope doesn’t extend beyond a single segment.</p><p>With that, we’ve pretty much hit the limits. The runtime doesn’t support running full-blown object-oriented applications, as it only distributes objects by transporting them, not by invoking them remotely.</p><h4>Implementation constraints</h4><p>Even within the procedural paradigm, there are a few important rules to follow to ensure everything runs smoothly, no matter the deployment model:</p><ol><li><strong>Modules</strong> must be stateless;</li><li><strong>Functions</strong> must be asynchronous;</li><li><strong>Data</strong> must be immutable.</li></ol><p>If you’ve worked on at least one distributed application, these rules probably won’t come as a surprise.</p><p>From our perspective, this creates some distance from our utopian vision, but only because of the second — asynchronous — rule. Keeping things stateless and sharing immutable data are already best practices for building resilient applications, even in monoliths.</p><p>In JavaScript, asynchronous functions must return a promise. Most developers (ourselves included) lean on the async / await keywords for their simplicity. But promises work perfectly well without them:</p><pre>/* imports */<br><br>export default function getMonthReport(year, month)<br>{<br>  return getMonthData(year, month)<br>    .then(formatMonthReport)<br>    .then(createPDF);<br>}</pre><p>Although this version does exactly the same as the async / await variant, our runtime won’t accept it and will throw an error. For good reason.</p><p>If segmented functions aren’t asynchronous, the application simply breaks. To prevent that, we check them during the build process. The simplest and safest method we’ve found is verifying that the function declaration includes the async keyword, which guarantees the function will always return a promise.</p><p>Yes, we know this makes the runtime a bit opinionated. We see it as a trade-off for the greater good… or maybe just a confession that we don’t fully trust ourselves to always get it right.</p><h4>Conditional meta-tasks</h4><p>Most frameworks use mechanics like middleware, decorators, or annotations to bind conditional tasks at meta-level to functionality, such as authorization, validation, etc.</p><p>In the third part of this series, I explained that we don’t want to support middleware at the procedure level to avoid turning our project into a framework. The same reasoning applies to avoiding TypeScript’s decorators. This leaves a gap that needs to be filled.</p><p>Due to the nature of the runtime, we don’t have many alternatives besides embedding these tasks directly into the business logic flows. For our own applications, we’ve established a pattern that’s actually quite simple.</p><p>For example, in our getMonthReport process, the validity of the input (year and month) needs to be checked before these values can be trusted and used. Our first step is to create a validator function.</p><pre>export default function validateMonthSelection(year, month)<br>{<br>  // validate values: throw error on invalid<br>}</pre><p>Since there’s little to no chance that validator functions will be placed in a different segment from their caller(s), we don’t consider it necessary to make them asynchronous.</p><p>Next, we need to decide where to call this validator function. We follow a simple rule: validate values at the point where they’re used.</p><p>In this case, the getMonthReport function passes the values to the getMonthData function, which actually uses them in a query. Therefore, the validation should be done there.</p><pre>import validateMonthSelection from &#39;./validateMonthSelection.js&#39;;<br><br>export default async function getMonthData(year, month)<br>{<br>  validateMonthSelection(year, month);<br><br>  /* retrieve and return data */<br>}</pre><p>We apply the same approach to all other types of tasks. Removing these tasks from the meta-level makes the code more explicit. For us, this is more of a gain than a loss.</p><h4>Error mediation</h4><p>I’ve lost count of how many times our “not a framework” goal has left its mark on the design of the runtime. In almost all impossible cases, we’ve either found a workaround (like the one above) or talked our way out of it (like with middleware and health checks). But this battle, we haven’t won yet…</p><p>As mentioned in the third part, to effectively deal with errors, the runtime and application need to “understand” each other’s errors. The only manageable solution we found was to create an intermediate error layer that both must use.</p><p>This forces the application to import errors from the runtime, creating a dependency we’d prefer to avoid. But until we have an alternative solution, we’ll just have to live with it. Fortunately, it’s fairly easy to limit the impact of this dependency.</p><p>The runtime provides a set of commonly used errors. Most applications — or at least all of ours — use this same set to set up the generic error tree. Extending the application’s set with the runtime’s is a low-effort step that we currently follow.</p><p>For example, to implement the validation error for month selection, we first extend the generic BadRequest error from the runtime.</p><pre>import { BadRequest as JitarBadRequest } from &#39;jitar&#39;;<br><br>export default class BadRequest extends JitarBadRequest {}</pre><p>We then extend this error to implement the specific validation error.</p><p>If, for whatever reason, we want to migrate away from the runtime, all we need to do is remove these dependencies, and we’re done. Well, aside from hard-coding the API’s and requests to make it work again, of course.</p><p>Pretty simple, right? Even if it’s not perfect.</p><p>Oh well. You know what they say: you win some, you deny some, and you lose some.</p><h3>Final words</h3><p>Congratulations, you’ve made it to the end! Quite an achievement, considering the length of the series and its individual parts.</p><p>To be honest, my intention was to write a single article. But once I started, it quickly turned into more. Or, as my business partner put it: “Are you writing a book?”. At that point, I decided to turn it into a series.</p><p>I could have done otherwise and published only the summary, but I’m glad I didn’t. This series has turned an important part of our decision records and designs into a story we can share. During development, we tend to focus on individual puzzle pieces, and this story helped us regain sight of the cohesive whole.</p><p>We still plan to publish a summarized version that focuses more on the mechanics rather than our considerations and decisions, so we can reach a broader audience. We’ll probably choose a catchier title than this one to attract more readers.</p><p>Our overall goal isn’t to spoon-feed our ideas and knowledge, but to create a broader platform for sharing insights and collaborating on ways to deal with architectural uncertainty. The runtime only addresses distribution uncertainties, but there’s a lot more ground to cover in this field.</p><p>We’re also open to contributions to the runtime in any form: opening issues, creating pull requests, or simply providing feedback. Even if you think this is the most ridiculous idea on the planet, we’d like to hear it.</p><p>And that’s it.</p><p>At least for now… As a follow-up, I want to write about building proper, scalable modular monoliths. By “scalable” I mean in terms of features, team, and infrastructure. It’s intended as a single article.</p><p>I’ll be thanking you again for reading in the closing of this article, but since that part is a bit generic — being part of the series template — I want to say something more personal here.</p><p>If you’re reading this and have followed all the previous parts, please know that my appreciation is truly sincere. I’m aware you’ve spent some of your valuable time on the array of characters I’ve produced, and that means a lot to me.</p><p>This series was made possible thanks to the help of my reviewers and, of course, the publisher. They absolutely deserve a big shout-out for all their effort and support.</p><p>Thank you!</p><p>Thank you for taking the time to read this article. I truly hope you’ve enjoyed its contents and will consider reading all parts.</p><p>If you have any questions or feedback, I would greatly appreciate it if you left a comment or reached out to me on Discord: <a href="https://discord.gg/Bqwy8azp5R">https://discord.gg/Bqwy8azp5R</a></p><p>The Jitar project and its source code can be found on GitHub: <a href="https://github.com/MaskingTechnology/jitar">https://github.com/MaskingTechnology/jitar</a></p><p>An example project that fully leverages Jitar’s features is available here: <a href="https://github.com/MaskingTechnology/comify">https://github.com/MaskingTechnology/comify</a></p><p>Thanks again for being here, take care!</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 3.5m monthly readers? <strong>We don’t receive any funding, we do this to support the community. ❤️</strong></p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a>, <a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. You can also subscribe to our <a href="https://newsletter.plainenglish.io/"><strong>weekly newsletter</strong></a>.</p><p>And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e84b04148f54" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54">The Anatomy of a Distributed JavaScript Runtime | Part V — Consolidation and conclusions</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of a Distributed JavaScript Runtime | Part IV — Distributing applications]]></title>
            <link>https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e9e9b7df54f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Mon, 04 Aug 2025 23:48:59 GMT</pubDate>
            <atom:updated>2025-08-12T08:45:53.830Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Anatomy of a Distributed JavaScript Runtime | Part IV — Distributing applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jLXU9IJJdsiQSiKPGKXJjg.png" /><figcaption>The scalpel is elevated, the runtime is down to earth (image by author)</figcaption></figure><p>In this article series, I’ll share how monolithic JavaScript (and TypeScript) applications can be split into distributed (micro)services with just configuration. We’ll explore the technical mechanics of this transformation and the principles for designing applications that embrace this duality.</p><p>The runtime we’ll be dissecting is Jitar. It’s fully open source, and you’ll find a link to the GitHub repository at the bottom of this article.</p><p>The series is divided into the following parts:</p><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe">Part I — Motivation and goals</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778">Part II — Splitting applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc">Part III — Running applications</a><br><strong>Part IV — Distributing applications</strong><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54">Part V — Consolidation and conclusions</a></p><p>If you’re only interested in the technical aspects, you can skip the first and last part. However, I recommend reading at least the first part to better understand the decisions made in the later sections.</p><h3>Part IV — Distributing applications</h3><p>In the previous part, we focused on the execution process of the distributable bundles. In this part, we’ll take the final step and explore the mechanics behind the distribution.</p><p>Our fourth design goal — simplified deployment — plays a key role in this. Distributed applications typically require a range of additional services for communication, fault tolerance, monitoring, and more. To simplify this complexity, we chose to integrate these capabilities directly into the runtime for both convenience and ease of use.</p><h3>Requirements</h3><p>Integrating these capabilities requires implementing the underlying infrastructure services essential for building scalable full-stack applications:</p><ul><li><strong>Worker</strong> — Loads and executes distributable bundles.</li><li><strong>Gateway</strong> — Routes execution requests to the appropriate worker.</li><li><strong>Repository</strong> — Serves static assets, such as the web client.</li><li><strong>Proxy</strong> — Combines the gateway/worker and repository into a single entry point.</li></ul><p>With these, we can set up and distribute our “Get monthly sales report” example from the previous parts like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*nCw7CQxVv6oN27h0" /></figure><p>Our goal was to make this setup work as follows: the client requests the report through the proxy. In the case of a web application, the frontend must be loaded first. Since this is a static asset request, the proxy forwards it to the repository. Once the frontend is loaded, it requests the formatted report using the RPC API. The proxy forwards this request to the gateway, which routes it to the reporting worker. In turn, the reporting worker requests the sales data from the gateway, which then routes it to the sales worker. Once the data is received, the report can be generated and sent back to the client.</p><p>Simple, right? Well… maybe not. I’ve deliberately created a comprehensive setup to demonstrate how the services work together. But for a simple application like this, such a complex setup is probably unnecessary. Since each service runs as its own instance of the runtime, it can also become quite costly. That’s why it’s time to introduce one of the runtime’s key requirements: <strong>standalone mode</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*o1kM4CCVhFTjkVCB" /></figure><p>In this mode, the runtime handles both the repository and worker responsibilities within a single instance. While production deployments may be distributed, standalone mode also simplifies development by eliminating the need to spin up dependent (or mock) services.</p><p>As mentioned in the previous part, the segment boundaries are respected regardless of their deployment, making this a viable option. Before diving deeper, we need a basic understanding of the runtime’s architecture to fully grasp how everything fits together.</p><h3>Architecture overview</h3><p>The architecture is designed around a modular runtime that supports both client and server environments, with a clear separation of responsibilities across services. Each component plays a distinct role in enabling distributed execution, seamless communication, and streamlined deployment.</p><p>From a high-level perspective, the architecture is structured as a set of concentric rings, with each ring adding a new layer of functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*nRD4oEpzylfDESwt" /></figure><p>Let’s peel back the onion from the outside in.</p><h4>Bootstrap</h4><p>This ring provides interfaces for its end users (that’s us). Since we’re aiming at full-stack applications we needed to create a separate interface for the server and web browser.</p><p>To make the runtime more accessible, we eventually implemented a <strong>CLI</strong> to bootstrap the build process or start one of the services on the server. More recently, we added an init command to scaffold a new application from one of our templates, as we plan to build more applications using this runtime.</p><p>For bootstrapping the frontend, we created a <strong>Vite plugin</strong>, as it’s currently the most widely adopted tool among popular frontend frameworks. The plugin’s main function is to create and include a specific bundle that sets up a client runtime with the segments assigned to the frontend.</p><h4>Runtime</h4><p>For the services to function correctly, several environmental concerns need to be addressed, such as protocol handling, data serialization, middleware, and monitoring. This is where the runtime comes in.</p><p>Since distributed systems are implementations of the client-server model, it’s probably no surprise that we provide separate runtime environments for both.</p><p>The <strong>client runtime</strong> is the simpler of the two. It is responsible only for handling local and remote requests. It sets up a worker connected to the gateway or proxy, which it uses for remote calls. Our Vite plugin is currently its only consumer, but it’s relatively easy to integrate into other applications if we decide to expand its use.</p><p>The <strong>server runtime</strong> is responsible for exposing the endpoints that define a service’s capabilities. Since it supports all underlying services, it must handle the full range of their use cases. It took us a few iterations to find the right approach, but we eventually got there. All I’ll say for now is that the server communicates only with a proxy.</p><h4>Service</h4><p>This is where all the services reside. Since they’ve already been introduced, there’s little more to add here. Their implementation details will be covered in the service design section below.</p><h4>Execution</h4><p>At the core is the execution process we focused on in the previous part. Its only consumer is the worker, as this is the only service responsible for executing procedures.</p><h3>Service design</h3><p>As mentioned above, the server runtime communicates exclusively with a proxy service. Since the proxy needs to support the same use-cases, it gives the server the perfect interface to interact with, simplifying its implementation. Hooray!</p><p>But wait… doesn’t this just push the complexity down a level? It does, but we found that handling it at the proxy level offers more flexibility and control.</p><p>In essence, the proxy combines a repository with another service that delegates the execution of a procedure. The first implementation was a simple reverse proxy and wasn’t even part of the service architecture. However, while exploring standalone mode, we gradually began to realize that the proxy could play a much more central role.</p><p>From that point on, the proxy evolved into a composition of two types of services:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*ujIdJXTH6B02B-aL" /></figure><p>Each type of service has a clear and distinct responsibility:</p><ol><li><strong>Provider</strong> — serves assets;</li><li><strong>Runner</strong> — executes procedures.</li></ol><p>Currently, the repository serves as the sole provider, while both the worker and the gateway act as runners.</p><p>With that, we’ve solved half the puzzle. To complete it, we identified two additional types of implementations that were missing:</p><ol><li><strong>Dummy</strong> — stubs for both provider and runner types;</li><li><strong>Remote</strong> — communicates with a distributed service.</li></ol><p>Okay, the dummy implementations might need some context. When starting the runtime as a repository, the server shouldn’t handle execution requests. Likewise, when running as a worker, it shouldn’t serve asset requests. However, since the server always requires both a provider and a runner implementation, we need a way to indicate that certain types of requests shouldn’t be handled. That’s exactly where the dummies come in.</p><p>Every service that is accessed remotely by another service requires a remote implementation. Currently, these include the repository, worker, and gateway. Remote implementations have a single responsibility: invoking the functionality of the actual remote service.</p><p>To distinguish them from their local counterparts, we refer to them internally as local and remote implementations. For example, LocalWorker and RemoteWorker.</p><p>And now, the server composability fun begins:</p><ul><li><strong>Worker</strong> = DummyProvider + LocalWorker;</li><li><strong>Gateway</strong> = DummyProvider + LocalGateway;</li><li><strong>Repository</strong> = LocalRepository + DummyRunner;</li><li><strong>Proxy</strong> = RemoteRepository + RemoteGateway;</li><li><strong>Standalone</strong> = LocalRepository + LocalWorker.</li></ul><p>Pretty simple, if you’d asked us.</p><h3>Scaling strategy</h3><p>To ensure the system can efficiently handle varying loads, we designed workers to scale horizontally by spinning up additional instances as needed. Workers register and deregister themselves with the gateway, enabling it to load-balance requests across available instances.</p><p>When it came to balancing units, we considered two options: per segment or per procedure. We chose the latter because, in practice, it’s the only viable approach. When a procedure is placed in multiple segments, it becomes nearly impossible to determine, in all cases, which segment should handle the request.</p><p>As a result, we implemented a worker balancer per fully qualified name (FQN). Currently, we support only a round-robin strategy, but we plan to add more strategies in the future.</p><p>Schematically, the process looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*TRSXTQ7AOtTl68RZ" /></figure><p>At true high load, components like the gateway and repository must also scale. However, we’ve intentionally scoped these concerns out of our runtime. At such a scale, specialized tools tailored to the specific application context are typically required. Our focus is on enabling scalable applications and basic provisioning. As such, we design the runtime to integrate with these external tools, rather than attempting to build and maintain everything ourselves.</p><p>We’d rather focus our efforts on the next step: dynamic split-offs and reintegrations. By leveraging monitoring metrics, we aim to detect which parts of the application are experiencing high load. We’re not there yet, but we do already have some basic monitoring in place.</p><h3>Monitoring strategy</h3><p>At the time of writing, all of our monitoring is focused on adding fault tolerance for workers. We track two key aspects:</p><ol><li><strong>Availability</strong> — Is the worker reachable?</li><li><strong>Health</strong> — Is the worker able to handle requests?</li></ol><p>While our implementations for both are fairly standard, it’s still worth spending a few words on them.</p><p>For availability monitoring, we use a heartbeat system in which each worker reports its current state to the gateway at fixed intervals. The gateway’s worker manager regularly checks whether workers have reported on time. If a worker misses a beat, it’s flagged as unavailable. If it misses multiple beats, it’s marked as disconnected and removed by the manager.</p><p>Health monitoring is based on a health check system. By default, a worker doesn’t have any health checks, since these are specific to its environment. Similar to middleware, health checks are treated as plugins that can be created using an interface provided by the runtime.</p><pre>// ExampleHealthCheck.ts<br><br>import { HealthCheck } from &#39;jitar&#39;;<br><br>export default class ExampleHealthCheck implements HealthCheck<br>{<br>    get name(): string { return &#39;example&#39;; }<br><br>    get timeout(): number | undefined { return undefined; }<br>    <br>    async isHealthy(): Promise&lt;boolean&gt; { /* ... */ }<br>}</pre><p>To generate a health overview, the name property is used to identify each check. The timeout property limits the response time for external resources, such as a database.</p><p>In addition to workers, the other services also manage their own health and state. For example, if a repository uses a network file system, a health check can be added to verify its availability.</p><p>When defining states, we aimed to keep things minimal. In our experience, fine-grained states tend to confuse more than they clarify. Here’s what we currently use:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*MtO5bhLJpgPmxdeR" /></figure><p>We intentionally left out healthy and unhealthy states, as their meaning and behavior are effectively identical to available and unavailable.</p><p>As you’d expect, the worker balancer only selects workers in the available state for execution. The next step is using these states to implement <strong>retry</strong> and <strong>circuit breaker</strong> patterns.</p><p>The server exposes endpoints that provide monitoring information, allowing integration with external monitoring systems. Since this is the third part I’ve mentioned endpoints without really explaining them, it’s time to dive into them a little deeper.</p><h3>Protocol handling</h3><p>To make the server’s endpoints accessible externally, we didn’t want to commit to a single protocol. Instead, we designed the runtime to be protocol-agnostic by implementing dedicated client and server components for each supported protocol.</p><p>Currently, we only support HTTP, but the runtime is fully equipped to support additional protocols like gRPC. This would allow us to use HTTP solely for frontend–backend communication, while leveraging the more efficient gRPC protocol for inter-service communication.</p><h4>HTTP implementation</h4><p>When it comes to HTTP-based APIs, REST is the most commonly used style. While we aimed to keep our implementation as RESTful as possible, the runtime is fundamentally built around remote procedures… So, adopting an RPC-style API was ultimately the only practical choice.</p><p>For convenience, we chose to support both the GET and POST methods for calling a procedure. While they achieve the same result, there are subtle differences in usage and limitations.</p><p>The GET method is ideal for small, simple requests and can even be used directly from a browser.</p><pre>GET http://localhost:3000/rpc/reporting/getMonthReport?year=2025&amp;month=8 HTTP/1.1</pre><p>For larger requests involving complex data, the POST method is a better fit, as it allows a request body and avoids URL length limitations.</p><pre>POST http://localhost:3000/rpc/reporting/getMonthReport HTTP/1.1<br>content-type: application/json<br><br>{<br>  &quot;year&quot;: 2025,<br>  &quot;month&quot;: 8<br>}</pre><p>As mentioned in the previous part, procedures can also be executed in dry mode, where all execution steps are performed except for the final call to the implementation function. This mode leverages the OPTIONS method.</p><pre>OPTIONS http://localhost:3000/rpc/reporting/getMonthReport?year=2025&amp;month=8 HTTP/1.1</pre><p>Our HTTP client implementation uses only the POST method to ensure that all arguments can be transferred without limitation. However, before sending the request, all data must be serialized.</p><h4>Data serialization</h4><p>To minimize limitations on supported data types, we searched for a serializer that could handle not only primitive values and plain JavaScript objects, but also built-in types like Map, Set, and Date, as well as custom classes. We found none.</p><p>This left us with two options:</p><ol><li>Pick the best available option and accept the limitations;</li><li>Try to build something better yourself.</li></ol><p>Initially, we favored the first option since it saves time on development and maintenance. There are quite a few libraries to choose from, some even quite advanced. However, they all lacked robust support for complex, nested custom classes, if they supported custom classes at all.</p><p>For us, this limitation was insurmountable. As explained in the second part, we favor a procedural style over object orientation when building business applications, given their workflow-oriented nature. However, this doesn’t mean custom classes are out of the picture. For instance, when building a data-driven form system with validations and transformations, you’d likely want to share these models across the application. At least, we would.</p><p>Long story short — after a few prototypes — we ended up building our own serializer that supports everything we need, including complex, nested custom classes with private fields. To build the class serializer, we leveraged our code analysis package (originally created for application splitting), which significantly simplified the creation of the serialization models.</p><p>As an example, let’s assume we want to serialise an instance of this Employee model class:</p><pre>// hr/Employee.ts<br><br>import type Address from &#39;../common/Address&#39;;<br><br>export default class Employee<br>{<br>  readonly #firstName: string;<br>  readonly #lastName: string;<br>  readonly #dateOfBirth: Date;<br><br>  #address?: Address;<br><br>  constructor(firstName: string, lastName: string, dateOfBirth: Date)<br>  {<br>    this.#firstName = firstName;<br>    this.#lastName = lastName;<br>    this.#dateOfBirth = dateOfBirth;<br>  }<br><br>  get address() { return this.#address; }<br><br>  set address(address: Address) { this.#address = address; }<br>}</pre><p>I’ve used TypeScript to clearly indicate the structure of the data an instance contains. In this case, the serializer needs to handle strings, a Date object, and another instance of a custom class.</p><p>So, if we were to serialize the following instance:</p><pre>import Address from &#39;./common/Address&#39;;<br>import Employee from &#39;./hr/Employee&#39;;<br><br>const johnDoe = new Employee(&#39;John&#39;, &#39;Doe&#39;, new Date(&#39;05 October 2001 00:00 UTC&#39;));<br>johnDoe.address = new Address(&#39;123 Main Street&#39;, &#39;Washington, DC 20500&#39;);</pre><p>The end result looks like this:</p><pre>{<br>  &quot;serialized&quot;: true,<br>  &quot;name&quot;: &quot;class&quot;,<br>  &quot;key&quot;: &quot;hr/Employee&quot;,<br>  &quot;args&quot;: {<br>    &quot;0&quot;: &quot;John&quot;,<br>    &quot;1&quot;: &quot;Doe&quot;,<br>    &quot;2&quot;: {<br>      &quot;serialized&quot;: true,<br>      &quot;name&quot;: &quot;Date&quot;,<br>      &quot;value&quot;: &quot;2001-10-05T00:00:00.000Z&quot;<br>    }<br>  },<br>  &quot;fields&quot;: {<br>    &quot;address&quot;: {<br>      &quot;serialized&quot;: true,<br>      &quot;name&quot;: &quot;class&quot;,<br>      &quot;key&quot;: &quot;common/Address&quot;,<br>      &quot;args&quot;: {<br>        &quot;0&quot;: &quot;123 Main Street&quot;,<br>        &quot;1&quot;: &quot;Washington, DC 20500&quot;<br>      },<br>      &quot;fields&quot;: {}<br>    }<br>  }<br>}</pre><p>Now, let’s explore the root structure:</p><ul><li><strong>serialized</strong> — Indicates whether the value needs to be deserialized before being used as an argument.</li><li><strong>name</strong> — The name of the object data type, used to select the appropriate value deserializer.</li><li><strong>key</strong> — Serves as a class identifier; in our case, this is the fully qualified name (FQN).</li><li><strong>args</strong> — The constructor arguments.</li><li><strong>fields</strong> — The public field or setter values.</li></ul><p>If you look closely, you’ll notice that the structure of the serialized date is quite similar. Every instance of a built-in type or custom class includes the serialized property to indicate that the value is not a plain JavaScript object, and the name property to specify its origin.</p><p>These two properties provide the key information needed to select the appropriate value deserializer. If neither is defined, the serializer treats the value as a primitive or a plain JavaScript object.</p><p>This logic might appear static, but its implementation is anything but. Under the hood, we leverage the Chain of Responsibility pattern to select the appropriate value (de)serializers. We’ve structured the chain in a way that enables this behavior. If new built-in types are introduced, we can easily extend or reorder the chain.</p><p>To enable the serializer, classes shared between segments must be registered in the receiving segment’s configuration. This ensures that the class is included in the segment bundle and can be resolved by its fully qualified name (FQN).</p><p>And with that, we’ve reached the end of this part and the technical deep dive into the runtime. In the next and final part, I’ll wrap up the series with conclusions and key considerations, such as the constraints involved in building applications that fully leverage the runtime.</p><p>Thank you for taking the time to read this article. I truly hope you’ve enjoyed its contents and will consider reading all parts.</p><p>If you have any questions or feedback, I would greatly appreciate it if you left a comment or reached out to me on Discord: <a href="https://discord.gg/Bqwy8azp5R">https://discord.gg/Bqwy8azp5R</a></p><p>The Jitar project and its source code can be found on GitHub: <a href="https://github.com/MaskingTechnology/jitar">https://github.com/MaskingTechnology/jitar</a></p><p>An example project that fully leverages Jitar’s features is available here: <a href="https://github.com/MaskingTechnology/comify">https://github.com/MaskingTechnology/comify</a></p><p>Thanks again for being here, take care!</p><h3>A message from our Founder</h3><p><strong>Hey, </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>Sunil</strong></a><strong> here.</strong> I wanted to take a moment to thank you for reading until the end and for being a part of this community.</p><p>Did you know that our team run these publications as a volunteer effort to over 200k supporters? <strong>We do not get paid by Medium</strong>!</p><p>If you want to show some love, please take a moment to <strong>follow me on </strong><a href="https://linkedin.com/in/sunilsandhu"><strong>LinkedIn</strong></a><strong>, </strong><a href="https://tiktok.com/@messyfounder"><strong>TikTok</strong></a><strong> and </strong><a href="https://instagram.com/sunilsandhu"><strong>Instagram</strong></a>. And before you go, don’t forget to <strong>clap</strong> and <strong>follow</strong> the writer️!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e9e9b7df54f" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f">The Anatomy of a Distributed JavaScript Runtime | Part IV — Distributing applications</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of a Distributed JavaScript Runtime | Part III — Running applications]]></title>
            <link>https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3400d66c15cc</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Thu, 24 Jul 2025 08:09:15 GMT</pubDate>
            <atom:updated>2025-08-12T08:45:32.196Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Anatomy of a Distributed JavaScript Runtime | Part III — Running applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jLXU9IJJdsiQSiKPGKXJjg.png" /><figcaption>The scalpel is feeling sharp, the runtime finds this blunt (image by author)</figcaption></figure><p>In this article series, I’ll share how monolithic JavaScript (and TypeScript) applications can be split into distributed (micro)services with just configuration. We’ll explore the technical mechanics of this transformation and the principles for designing applications that embrace this duality.</p><p>The runtime we’ll be dissecting is Jitar. It’s fully open source, and you’ll find a link to the GitHub repository at the bottom of this article.</p><p>The series is divided into the following parts:</p><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe">Part I — Motivation and goals</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778">Part II — Splitting applications</a><br><strong>Part III — Running applications</strong><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f">Part IV — Distributing applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54">Part V — Consolidation and conclusions</a></p><p>If you’re only interested in the technical aspects, you can skip the first and last part. However, I recommend reading at least the first part to better understand the decisions made in the later sections.</p><h3>Part III — Running applications</h3><p>In the previous part, we split a monolithic application into separately distributable bundles. In this part, we’ll focus on taking those bundles and executing them.</p><p>Our third design goal — simplified development — really comes to life here. During development, we want to run the application as a monolith, distributing it only in production. However, we also want the flexibility to temporarily distribute a single segment to handle a sudden spike in load, and then reintegrate it into the monolith once the load decreases.</p><h3>Prerequisites</h3><p>In addition to flexible deployments, we also want reliable deployments. By this, we mean that the application should behave identically, regardless of how it is deployed. For example, if a procedure is marked as private, it must remain inaccessible to other segments, even when everything runs in a single process. This guarantees consistent behavior across all environments.</p><p>To achieve this, we must ensure that segment boundaries are respected, even in a monolithic deployment. Our bundling strategy already accounts for this by ensuring that every cross-segment call is handled by the runtime. The remaining responsibility lies with the execution itself.</p><h3>Executing procedures</h3><p>The runtime provides several services, one of which is responsible for executing procedures: the worker. At startup, the worker builds an application model from the configured segments. Depending on the configuration, this may represent the entire application or just a part of it. The application model, including the segment model, looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*hYPrhCrHn81XEVdt" /></figure><p>Once the segments are loaded and their models initialized, the runtime is ready for execution. As mentioned in the previous part, the built-in __run function is responsible for managing the execution process.</p><p>As a refresher, let’s look at the generated remote procedure example from the previous part.</p><pre>export default async function getMonthData(year, month)<br>{<br>  return __run(&#39;sales/getMonthData&#39;, &#39;0.0.0&#39;, { &#39;year&#39;:year, &#39;month&#39;:month }, this);<br>}</pre><p>It plays a critical role in handling both inbound and outbound procedure calls between segments. Regardless of direction, the execution flow remains consistent.</p><h4>Execution process</h4><p>Depending on the deployment model, a procedure might be available either locally or remotely. If the calling segment and the target segment are deployed together, the procedure is available locally, and no remote call is necessary. However, before executing the target function, its access permissions must be validated. If the function is configured as private, execution must be denied.</p><p>When segments are deployed separately, a remote call is required. In that case, the call must be translated into a request and transported over the configured protocol. On the receiving end, the inbound request is translated back into a call and processed just like a local one, including permission checks.</p><p>Schematically, the process looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*zk66KCFhP4FkzXD3" /></figure><p><strong>Note</strong> that this process does not yet involve the protected access level, as that applies to the actual remote request layer. I’ll cover those details later.</p><h4>Request model</h4><p>To bootstrap this process, the __run function needs information that defines what to execute and how to execute it. This data is gathered from the function’s module, name, and parameters, before organizing it into a single request model. Our model includes the following fields:</p><ul><li><strong>FQN</strong> (Fully Qualified Name) — procedure identifier (string);</li><li><strong>Version</strong> — implementation selection (object);</li><li><strong>Arguments</strong> — function parameters (key/value pairs);</li><li><strong>Headers</strong> — metadata (key/value pairs);</li><li><strong>Run mode</strong> — function execution (predefined options).</li></ul><p>The <strong>FQN</strong> field is used to uniquely identify procedures. It combines the module’s root path with the name of the function (by default, the function’s export identifier). This structure ensures uniqueness, which is essential for accurate procedure resolution. Based on our example…</p><pre>// reporting/getMonthReport.js<br><br>import createPDF from &#39;../utils/createPDF.js&#39;;<br>import getMonthData from &#39;../sales/getMonthData.js&#39;;<br>import formatMonthReport from &#39;./formatMonthReport.js&#39;;<br><br>export default async function getMonthReport(year, month)<br>{<br>  /* implementation */<br>}</pre><p>…the FQNs are:</p><pre>reporting/getMonthReport<br>reporting/formatMonthReport<br>sales/getMonthData<br>utils/createPDF</pre><p>From these FQNs, the worker creates endpoints for all non-private procedures to expose them to the outside world. These endpoints are used internally by the runtime’s other services, which will be explained in the next part about our distribution approach.</p><p>The endpoints are also available to external clients for integration with other systems. From experience, we know how important backward compatibility is when relying on external services. Therefore, we consider API versioning a must-have feature in our runtime. The <strong>version</strong> field is used to select the appropriate implementation of a procedure. Details on managing versions will be covered in a later section.</p><p>To execute a procedure implementation, arguments must be provided for its parameters. The most straightforward and reliable way we’ve found to map these arguments is by name, as this avoids confusion that can arise from relying on their order. All parameters are considered required unless a default value is defined.</p><pre>export default async function getMonthReport(year, month = 9)<br>{<br>  /* implementation */<br>}</pre><p>In this example, only the year parameter is required. An error will be thrown if the request does not provide a value for it. At this point, this is the only validation that takes place. We’ve deliberately kept data validation out of scope, for reasons that will be explained in the final part of this series.</p><p>The <strong>FQN</strong>, <strong>version</strong>, and <strong>arguments</strong> are the essential fields required to run a procedure. Additionally, the worker or environment may require supplementary information to properly process the request. For example, a trust key for executing protected procedures or CORS settings in an HTTP context. Such meta-information is passed through the <strong>headers</strong> field.</p><p>While most requests follow the execution process as described, certain scenarios require a preliminary check of the environment to validate the setup before actual execution. A good example is handling a CORS preflight request. To support this, we’ve implemented two run modes: <strong>normal</strong> and <strong>dry</strong>. In <strong>dry</strong> mode, all execution steps are carried out — including middleware processing — with the exception of the final call to the implementation function.</p><h4>Response model</h4><p>Now that we understand the input, let’s complete the picture by examining its output: the response. Our response model includes the following fields:</p><ul><li><strong>Result</strong> — returned value or thrown error (any type of data);</li><li><strong>Status</strong> — result interpretation (predefined options);</li><li><strong>Headers</strong> ​​ — metadata (key/value pairs).</li></ul><p>The <strong>result</strong> field contains the value returned — or thrown — by the procedure. It can be of any data type, as we aim to avoid placing restrictions on implementation logic.</p><p>To indicate whether a procedure returned a value successfully or encountered an error, the <strong>status</strong> field is used. For failed requests, we’ve defined various status codes to support more granular and accurate error handling. More details will be provided in the error handling section.</p><p>Like requests, responses can also include meta-information in the form of <strong>headers</strong>, allowing the worker or environment to react accordingly.</p><h4>Fitting it together</h4><p>With these concepts in place, it’s time to complete the puzzle. When a remote procedure is invoked, the __run function is called, and a request object is created from its arguments. The essential data (FQN, version, and arguments) are extracted directly from the function arguments, but meta-data (headers and run mode) are not. Notice the this argument passed as the final parameter to the __run function? That’s where the fun begins… but let’s start at the beginning.</p><p>To avoid becoming a framework, the runtime uses plain functions as procedures. While this works quite straightforwardly for the biggest part, passing meta-data is anything but. We didn’t want to require an extra parameter in every function signature, like this:</p><pre>export default async function getMonthReport(year, month, metaData)<br>{<br>  /* implementation */<br>}</pre><p>So, we needed an alternative that could pass the meta-data under the hood. One option was to secretly inject the parameter during the application rewriting phase. While technically workable, this approach would significantly complicate the rewriting process. Even if we were willing to take on that complexity, it still wouldn’t be a satisfactory solution. Modifying the application code beyond its imports introduces the risk of breaking functionality and reduces debuggability. So, we continued searching for a better solution.</p><p>As you’ve probably guessed, this is where the this argument comes into play. When a procedure function is called, the current request object is set as its thisArg. This allows the request data to propagate through the call stack, making it accessible to any remote procedures invoked by the implementation function. If a procedure is not available locally, the request is translated into an actual remote call.</p><p>Is this the perfect solution we were hoping for? No, it’s not. Arrow functions don’t have their own this binding, so they can’t be safely used in the application. This is a limitation we’re willing to accept, at least for now.</p><p>To close the loop, the meta-data is extracted from the source request provided by the thisArg and used to construct the new request. The availability of a source request depends on the origin of the invocation. External calls made through the RPC API include the full request data, while internal invocations do not. In such cases, an initial request is created before the execution process begins. This request always uses the normal run mode, as dry runs can only originate from external requests, where middleware is applied.</p><h3>Middleware</h3><p>The core function of the runtime is to split applications into distributable bundles and wire them back together by automating communication between the bundles. One of our key concerns with this approach was the potential loss of control over essentials like authentication, authorization, and logging. To address this, we implemented middleware support so these concerns can be easily injected.</p><p>For the implementation of the middleware support, we aimed to keep it as close as possible to familiar patterns from other implementations. When it comes to defining middleware, we believe we came very close.</p><pre>// ExampleMiddleware.ts<br><br>import { Middleware, Request, Response, NextHandler } from &#39;jitar&#39;;<br><br>export default class ExampleMiddleware implements Middleware<br>{<br>    constructor(/* ... */) { /* ... */ }<br><br>    async handle(request: Request, next: NextHandler): Promise&lt;Response&gt;<br>    {<br>        // Modify the request (args and headers) here<br><br>        const response = await next();<br><br>        // Modify the response (result and headers) here<br><br>        return response;<br>    }<br>}</pre><p>As mentioned in the first part, we chose to treat middleware as runtime plugins to maximize flexibility. The consequence of this approach is that middleware must conform to certain abstractions in order to work. Since the runtime is built with TypeScript, all necessary types are available to help us with this.</p><p>For the registration and execution of middleware, we had two options:</p><ul><li><strong>Generic</strong> — registered once and applied to all requests;</li><li><strong>Specific</strong> — registered per procedure and applied only to their requests.</li></ul><p>While some types of middleware, like request logging and authentication, are more generic by nature, others — such as authorization and validation — are more procedure-specific. So, the most logical decision would be to support both. We didn’t do that.</p><p>Use cases for specific middleware are closely related to, or even part of the domain logic. Allowing them to be implemented as middleware would essentially turn the runtime into a framework. Since we’re deliberately trying to avoid that, we drew the line there and only added support for generic middleware.</p><p>Procedure-specific concerns must therefore be implemented elsewhere. In the final part of this series, I’ll share how we handle this in our applications. Generic middleware can be added to workers and other service types through their configuration. How this works will be explained in more detail in the next part.</p><p>All middleware is executed for inbound requests at the service level, such as in a worker. To prevent middleware from being executed during cross-local segment calls, we’ve decoupled it from the execution process, as this could lead to unexpected behavior.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*UI6e2-DHdZ-1uBny" /></figure><p>The easiest way we found to achieve this was to wrap the execution in its own middleware and register it as the last one, ensuring it’s executed last. A simple trick that works remarkably well.</p><h3>API versioning</h3><p>Implementing breaking changes in a full-stack monolithic application is fairly easy compared to a decoupled one. Since components are connected via imports, usages are easy to track. Adding a type system like TypeScript helps even more, as it provides end-to-end type safety. Supported IDEs will immediately indicate which components break, even after a small change.</p><p>But this only works within the scope of a single application. Almost every application we’ve built has been part of a larger system or ecosystem, so we found it important to make the generated endpoints available to external systems as well. To manage breaking changes for those clients, we felt we had no choice but to support multiple versions of procedures.</p><p>Versions are implemented as separate functions and registered in the segment configuration. For example, let’s assume the getMonthReport function now accepts an additional parameter for selecting a formatting style, such as <em>comprehensive</em> or <em>concise</em>.</p><pre>// reporting/getMonthReport.js<br><br>/* imports */<br><br>export default async function getMonthReport(year, month, style)<br>{<br>  const data = await getMonthData(year, month);<br>  const report = await formatMonthReport(data, style);<br>  return createPDF(report);<br>}</pre><p>For backwards compatibility, we need to add a legacy function that doesn’t require the style parameter and simply applies a default choice.</p><pre>// reporting/getMonthReportLegacy.js<br><br>/* imports */<br><br>const DEFAULT_STYLE = Styles.COMPREHENSIVE;<br><br>export default async function getMonthReport(year, month)<br>{<br>  const data = await getMonthData(year, month);<br>  const report = await formatMonthReport(data, DEFAULT_STYLE);<br>  return createPDF(report);<br>}</pre><p>Next, we need to register both functions separately in the segment configuration, each with its own unique version.</p><pre>{<br>  &quot;./reporting/getMonthReport.js&quot;: {<br>    &quot;default&quot;: {<br>        &quot;access&quot;: &quot;public&quot;,<br>        &quot;version&quot;: &quot;2.0.0&quot;<br>    }<br>  },<br>  &quot;./reporting/getMonthReportLegacy.js&quot;: {<br>    &quot;default&quot;: {<br>        &quot;access&quot;: &quot;public&quot;,<br>        &quot;version&quot;: &quot;1.0.0&quot;<br>    }<br>  }<br>}</pre><p>Alternatively, both functions can be placed in the same module file and exported under different names.</p><pre>{<br>  &quot;./reporting/getMonthReport.js&quot;: {<br>    &quot;getMonthReport&quot;: {<br>        &quot;access&quot;: &quot;public&quot;,<br>        &quot;version&quot;: &quot;2.0.0&quot;<br>    },<br>    &quot;getMonthReportLegacy&quot;: {<br>        &quot;access&quot;: &quot;public&quot;,<br>        &quot;version&quot;: &quot;1.0.0&quot;,<br>        &quot;as&quot;: &quot;getMonthReport&quot;<br>    }<br>  }<br>}</pre><p>In this second approach, the export names no longer match, resulting in different FQNs. To address this, we introduced the as property to manually override the export name.</p><p>Now, both functions are available under the same FQN, distinguished by their version numbers. For the versioning strategy, we chose to use Semantic Versioning (SemVer), as it is the most widely adopted versioning standard.</p><p>For procedure execution, we favored flexibility over strict version precision. Requests don’t need to specify an exact available version number. For example, if a procedure is requested with version 1.1.1, the runtime will first look for an exact match. If none is found, it will select the highest available implementation with a lower version. In this case, the legacy version would be selected.</p><p>Schematically, the selection process looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/0*AAGF3UwB8fQ7VBT2" /></figure><p>Currently, we don’t support selecting a higher compatible version, even if one is available. We’re still evaluating whether this is something we want or need to support.</p><h3>Handling errors</h3><p>Operating at the runtime level can sometimes be confusing, especially when it comes to error handling. In addition to application errors, we also have to account for runtime errors. Occasionally, the two need to be combined or handled together.</p><p>Our basic strategy is to propagate all errors to the application. For example, if the application calls a function from another segment and it fails, the cause could be either an expected application error or a runtime error. Simply accounting for these unexpected errors in the application — besides being a good practice — solves most of this issue. However, the application isn’t able to fully interpret or respond to runtime errors.</p><p>Now consider the opposite scenario, where the application throws an error that the runtime needs to understand. For example, when the application could not find the requested resource, and needs to effectively communicate this with an external HTTP client by setting the appropriate response status code.</p><p>Fully supporting both scenarios requires an intermediate error layer to communicate issues such as bad requests, forbidden access, unauthorized access, not found, internal errors, etc., and to translate them into appropriate response status codes.</p><p>Since this conflicts with our “not a framework” goal, we initially tried to avoid it as much as possible. However, we eventually needed this support in our applications and were forced to implement it. We’re still exploring a less coupled solution, even though we’ve found a way to limit the dependency in our applications. I’ll share more about our approach in the final part of this article series.</p><p>Before the final part, there’s just one more to go. In that part we’ll explore the remaining runtime services and how they support application distribution.</p><p>Thank you for taking the time to read this article. I truly hope you’ve enjoyed its contents and will consider reading all parts.</p><p>If you have any questions or feedback, I would greatly appreciate it if you left a comment or reached out to me on Discord: <a href="https://discord.gg/Bqwy8azp5R">https://discord.gg/Bqwy8azp5R</a></p><p>The Jitar project and its source code can be found on GitHub: <a href="https://github.com/MaskingTechnology/jitar">https://github.com/MaskingTechnology/jitar</a></p><p>An example project that fully leverages Jitar’s features is available here: <a href="https://github.com/MaskingTechnology/comify">https://github.com/MaskingTechnology/comify</a></p><p>Thanks again for being here, take care!</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏️<strong>️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3400d66c15cc" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc">The Anatomy of a Distributed JavaScript Runtime | Part III — Running applications</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of a Distributed JavaScript Runtime | Part II — Splitting applications]]></title>
            <link>https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/321762404778</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[modular-monolith]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 10:24:12 GMT</pubDate>
            <atom:updated>2025-08-12T08:45:19.923Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Anatomy of a Distributed JavaScript Runtime | Part II — Splitting applications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jLXU9IJJdsiQSiKPGKXJjg.png" /><figcaption>The scalpel is closing in, the runtime knows it (image by author)</figcaption></figure><p>In this article series, I’ll share how monolithic JavaScript (and TypeScript) applications can be split into distributed (micro)services with just configuration. We’ll explore the technical mechanics of this transformation and the principles for designing applications that embrace this duality.</p><p>The runtime we’ll be dissecting is Jitar. It’s fully open source, and you’ll find a link to the GitHub repository at the bottom of this article.</p><p>The series is divided into the following parts:</p><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe">Part I — Motivation and goals</a><br><strong>Part II — Splitting applications<br></strong><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc">Part III — Running applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f">Part IV — Distributing applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54">Part V — Consolidation and conclusions</a></p><p>If you’re only interested in the technical aspects, you can skip the first and last part. However, I recommend reading at least the first part to better understand the decisions made in the later sections.</p><h3>Part II — Splitting applications</h3><p>In the previous part, we discussed the motivation, design goals, and technology choices of our runtime. In this part, we’ll dive deeper into the mechanics of splitting applications into distributable bundles.</p><p>As introduced in the first part, we need to separate the development model from the deployment model in order to enable dynamic application splitting. This led us to our first question: <em>How on earth are we going to achieve that?</em></p><p>Time to dive in. Before zooming in on the splitting process, we need something to split: an application.</p><h3>Writing distributable monoliths</h3><p>Distributing a big ball of mud probably isn’t a great idea, if it’s even possible at all. So, to make this approach work effectively, the application needs to meet certain requirements. I believe this quote by Simon Brown fits perfectly here:</p><blockquote>If you can’t build a well-structured monolith, what makes you think you can build a well-structured set of microservices?</blockquote><p>In the first part, I mentioned that a well-structured modular monolith is essentially the non-distributed version of microservices. That’s the key idea here.</p><p>The most fundamental requirement for a well-structured monolith is having clearly defined boundaries. So the key question becomes: what are these boundaries and how do we define them?</p><p>To explore that, let’s walk through a simple example: a business process for generating monthly sales reports, broken down into three straightforward steps.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*tpwNgjqnB5VE4I4H" /></figure><p>Now, let’s talk about the implementation.</p><p>JavaScript is a multi-paradigm language, which means we need to choose between an object-oriented (OO) or procedural approach. For building business applications and automating processes, I prefer the procedural style. It’s cleaner, simpler, and fits the context better.</p><p>More importantly, it makes automating end-to-end communication in a distributed setup much easier. While the runtime does support distributing OO applications, that route tends to be far less efficient due to the added complexity of managing object state across distributed nodes. I’ll go into more detail on that in the last part of this series.</p><p>More important for now is what the actual code looks like:</p><pre>// reporting/getMonthReport.js<br><br>import createPDF from &#39;../utils/createPDF.js&#39;;<br>import getMonthData from &#39;../sales/getMonthData.js&#39;;<br>import formatMonthReport from &#39;./formatMonthReport.js&#39;;<br><br>export default async function getMonthReport(year, month)<br>{<br>  const data = await getMonthData(year, month);<br>  const report = await formatMonthReport(data);<br>  return createPDF(report);<br>}</pre><p>This example represents the process module, which imports each step as an external function and exports a single process function.</p><p>Internally, we refer to this as the manager-expert pattern: the manager function orchestrates the workflow by delegating specific tasks to expert functions. This approach naturally decomposes processes into modular steps, making the code easier to read, maintain, extend, and… distribute.</p><p>In this example, each function is placed in its own module file, grouped by domain concept. We value this pattern because it provides the most flexibility when it comes to distribution.</p><p>There are also some rules of engagement for the implementation. Functions must be asynchronous to allow for remote calls, which means both the function itself and its callers need to be designed with this in mind. This can introduce some overhead, so it’s an important consideration during development. Additionally, the functions must be stateless in their implementation.</p><h3>Splitting the monolith</h3><p>In essence, it all boils down to replacing internal function calls with remote ones for the distributed parts. Sounds simple, right? With the JavaScript module system, it actually is — in theory…</p><p>The JavaScript module system provides an ideal foundation for building scalable solutions. Modules encapsulate their content within a private scope, establishing strong boundaries necessary for secure and efficient distribution. By leveraging this system, we can easily divide an application into distributable components.</p><p>JavaScript dynamically imports external modules from specified locations. Gaining control over this import mechanism allows us to inject custom logic, such as remote procedure calls, into the process. There are several approaches to achieve this, each with its own set of trade-offs.</p><p>Since the runtime is built as a layer on top of Node.js, the natural starting point is to leverage the <strong>custom module loader hook</strong>. However, this approach turned out to be unviable. The hook remains unstable, making it a risky choice for production. But more importantly, our design goal of automating frontend-backend communication requires a solution that also works seamlessly in the browser. Since Node.js is a backend runtime, this is a limitation that can’t be overcome.</p><p>The second, still relatively straightforward, option is to use a <strong>shared remote repository</strong> as a mediator, handling all import requests across parties. From the browser’s perspective, this approach works seamlessly, as modules are typically loaded from remote locations. However, Node.js prohibits remote module loading by default. Before version 22, Node.js had an experimental feature enabling remote loading, but this was removed due to significant security concerns. While we could implement a custom remote loader hook to bypass this limitation, it doesn’t address the security issues.</p><p>So far, not so good. Both of these approaches come with inherent limitations and risks, primarily because they operate at the request level. To overcome these challenges, we needed to rethink the approach and steer towards a solution that avoids dynamic module loading altogether. This brings us to the third and currently adopted solution: <strong>rewiring the application</strong> before execution<strong>.</strong></p><p>To distribute an application in any form, we can never be certain which modules will be distributed and which will remain local. As a result, simply replacing every import with a remote procedure call isn’t feasible, as it would disrupt local imports and break the application. To address this, we need a clear distribution plan to ensure everything functions as expected.</p><h3>Setting up a distribution plan</h3><p>Let’s say we want to distribute the example into two separate services: a reporting service and a sales service, each containing its related modules.</p><p>Since we want to keep configuration out of the code, we need an external mechanism to group the module files that need to be deployed together. In the context of JavaScript, JSON is a particularly suitable option.</p><p>For instance, the configuration for the reporting service might look like this:</p><pre>[<br>  &quot;./reporting/getMonthReport.js&quot;,<br>  &quot;./reporting/formatMonthReport.js&quot;<br>]</pre><p>While this approach is straightforward, it lacks flexibility. For example, we might want to add more configuration options, such as security concerns.</p><p>Modules can export multiple functions, but not all of them need to be accessible remotely. We needed a way to define which exported functions should be exposed. Additionally, some of these functions may need to be available only in a private or protected environment.</p><p>Considering these constraints, we came up with the following configuration structure for the reporting service:</p><pre>{<br>  &quot;./reporting/getMonthReport.js&quot;: {<br>    &quot;default&quot;: { &quot;access&quot;: &quot;public&quot; }<br>  },<br>  &quot;./reporting/formatMonthReport.js&quot;: {<br>    &quot;default&quot;: { &quot;access&quot;: &quot;private&quot; }<br>  }<br>}</pre><p>In this configuration, only the <strong>default</strong> exports are defined, because each function has its own module in our example. The getMonthReport function is set to <strong>public</strong> access, making it accessible to external clients, including untrusted ones. In contrast, the formatMonthReport function is marked as <strong>private</strong>, meaning it cannot be accessed externally.</p><p>The configuration for the sales service looks like this:</p><pre>{<br>  &quot;./sales/getMonthData.js&quot;: {<br>    &quot;default&quot;: { &quot;access&quot;: &quot;protected&quot; }<br>  }<br>}</pre><p>The getMonthData function is set to <strong>protected</strong> access, meaning it’s only accessible to trusted external clients. I’ll share more details about the access levels later on.</p><p>With the distribution plan now configured, we can proceed to rewire the application. In our terminology, these services are referred to as <strong>segments</strong>, as they represent isolated parts of the application. A segment can function as a service or take on other roles, offering flexibility in how the application is distributed and deployed.</p><h3>Rewiring an application</h3><p>First, let’s define what we mean with <strong>rewiring</strong>. In simple terms, it involves replacing internal imports with remote procedure calls whenever an import comes from another <strong>segment</strong>. Take a moment to let that sink in.</p><p>Before we can replace an import, we first need to create a remote procedure to substitute it. The simplest approach we found is to create a <strong>drop-in replacement</strong> function that performs the remote call. For example, for the getMonthData function, this would look like this:</p><pre>export default async function getMonthData(year, month)<br>{<br>  // Do remote call<br>}</pre><p>This remote function retains the same signature as the original function but implements the logic to make the remote call.</p><p>The easiest way to implement the call is by using the standard <strong>Fetch API</strong>. However, this approach presents two challenges:</p><ol><li>The remote URL is only determined at runtime.</li><li>Segments may be deployed together, and in such cases, we want to avoid performing a remote call.</li></ol><p>Considering both of these factors in the remote function would introduce unnecessary complexity. A better approach is to delegate this responsibility to the <strong>runtime</strong>, which has all the information it needs to make the correct call. This allows us to do something like:</p><pre>export default async function getMonthData(year, month)<br>{<br>  return __run(&#39;sales/getMonthData&#39;, &#39;0.0.0&#39;, { &#39;year&#39;:year, &#39;month&#39;:month }, this);<br>}</pre><p>This is not just a random example: the runtime will produce this exact output. The __run function is defined globally by the runtime and handles the call. Its details will be explained in the next part where we’ll dive into the execution of an application.</p><p>For now, it’s important to know that remote functions will be generated for each public function from a segmented module. The output will be saved in a separate remote module file, which can be substituted in the calling file:</p><pre>// Before<br>import getMonthData from &quot;../sales/getMonthData.js&quot;;<br><br>// After<br>import getMonthData from &quot;../sales/getMonthData.remote.js&quot;;</pre><p>This process rewires the calling module file and saves it as a new copy:</p><pre>// reporting/getMonthReport.reporting.js<br><br>import createPDF from &#39;../utils/createPDF.js&#39;;<br>import getMonthData from &#39;../sales/getMonthData.remote.js&#39;;<br>import formatMonthReport from &#39;./formatMonthReport.js&#39;;<br><br>/* … */</pre><p><strong>Note</strong> that the filename of the copy includes the <strong>segment name</strong>. Since modules can appear in multiple segments, the import rewrites are relative to the segment in which the module is placed. Therefore, module files must be segment-specific. If a module appears in multiple segments, a separate copy will be generated for each segment to avoid conflicts.</p><p>This also means that imports within the same segment must be <strong>rewired</strong> to point to their segment-specific copy. For example, we need to rewire the import for formatMonthReport:</p><pre>// reporting/getMonthReport.reporting.js<br><br>import createPDF from &#39;../utils/createPDF.js&#39;;<br>import getMonthData from &#39;../sales/getMonthData.remote.js&#39;;<br>import formatMonthReport from &#39;./formatMonthReport.reporting.js&#39;;<br><br>/* … */</pre><p>With this, we’ve completed the rewiring of segmented modules. Next, we needed to deal with the <strong>unsegmented modules</strong>, such as the createPDF utility function.</p><p>We think it’s fair to say that unsegmented modules can be considered shared across all segments. This means we don’t need to rewire their imports, since there’s nothing particularly special about them. At least, that’s what we thought until we discovered that ‘shared’ can mean different things depending on the context. Let me explain.</p><p>Most modules are, or should be, stateless to avoid breaking the application during splitting and distribution. However, there are cases where sharing state is desirable, especially when deploying multiple segments together that need access to shared resources like a database. In such cases, leaving the import untouched might seem like the right choice, until we reach the next step: <strong>creating independently deployable segment bundles</strong>.</p><p>This is when issues arise, as each bundle will have its own version of the module. So, even if the modules are technically the same, they might not behave the same when bundled. But, before diving into bundling, let’s wrap up this step first.</p><p>In our terminology, stateless unsegmented modules are referred to as <strong>common modules</strong>, while stateful ones are called <strong>resource modules</strong>. Common modules<strong> </strong>can be bundled without issues, but resource modules must be excluded from bundling to maintain shared state across segments.</p><p>By default, most bundlers only include static imports, so to prevent the bundling of resource modules, we can use <strong>dynamic imports</strong>.</p><p>For example, the createPDF function would look like this:</p><pre>// reporting/getMonthReport.reporting.js<br><br>const { default: createPDF } = await import(&#39;../utils/createPDF.js&#39;);<br>import getMonthData from &#39;../sales/getMonthData.remote.js&#39;;<br>import formatMonthReport from &#39;./formatMonthReport.reporting.js&#39;;<br><br>/* … */</pre><p>At this stage, only the imports are modified; the rest of the module remains unchanged until bundling.</p><p>To distinguish between a <strong>common</strong> and a <strong>resource</strong> module, resources can be configuredin a <strong>JSON file</strong>, like this:</p><pre>[<br>  &quot;./utils/createPDF.js&quot;<br>]</pre><p>To recap, here is a schematic view of our rewiring process per import.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*_OliV_djYMfBBi1f" /></figure><p>And here’s the complete example after this step:</p><pre>// reporting/getMonthReport.reporting.js<br><br>const { default: createPDF } = await import(&quot;../utils/createPDF.shared.js&quot;);<br>import getMonthData from &quot;../sales/getMonthData.remote.js&quot;;<br>import formatMonthReport from &quot;./formatMonthReport.reporting.js&quot;;<br><br>export default async function getMonthReport(year, month)<br>{<br>  const data = await getMonthData(year, month);<br>  const report = await formatMonthReport(data);<br>  return createPDF(report);<br>}</pre><p>In this way, all module files will be rewired, effectively rewriting the entire application. All generated files are written to a separate output folder, replicating the application structure.</p><h3>Generating distributable bundles</h3><p>To distribute segments across the network, we need a packaged bundle that can be easily deployed without the need to select each file individually. Manually picking out and deploying files would be tedious and error-prone.</p><p>Since JavaScript originates from the web, bundling multiple files into a single package is a common practice for performance optimization. Bundling is often combined with <strong>minification</strong> to reduce file sizes, which is essential for frontend code. However, on the backend, the benefits of minification are less significant. In our case, bundling solves our distribution problem by consolidating multiple files into one, but without the minification step.</p><p>The simplest way to define our bundles systematically is by creating a segment-specific module that re-exports the public and protected entries from all the application module files that have been configured for that segment.</p><p>Here’s an example:</p><pre>// reporting.segment.js<br><br>export { default as getMonthReport } from &quot;./reporting/getMonthReport.reporting.js&quot;;<br>export { default as formatMonthReport } from &quot;./reporting/formatMonthReport.reporting.js&quot;;</pre><p>Once this file is created, feeding it into any modern bundler, like <strong>Webpack</strong>, <strong>Rollup</strong>, or <strong>Turbopack</strong> will be enough to produce a deployable package.</p><p>While this is already a big step forward, we still need to incorporate additional information from the segment configuration to fully automate the creation of endpoints, such as <strong>fully qualified names (FQNs)</strong> and <strong>versions</strong> (for API versioning). Instead of deploying and side-loading the segment configurations separately, it’s more efficient to integrate this information directly into the segment bundle.</p><p>To track a segment’s contents and handle remote procedure calls, we need an internal model to store the necessary information. This model can either be built dynamically during the segment’s loading process, or it can be statically baked into the segment bundle itself. The latter approach is more efficient because it eliminates the need for additional transformations during the loading phase.</p><p>This segment model essentially holds two key components:</p><ol><li><strong>Procedures</strong> (functions) — These are versioned, meaning there can be multiple implementations of the same procedure over time.</li><li><strong>Classes</strong> — These are registered so that their objects can be shared via serialization, making them suitable for remote communication.</li></ol><p>Visually, our model looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/0*wo7zz_GHu2YWZL4k" /></figure><p>To register implementations, we need to extract their parameters in order to map and verify the arguments provided during a remote-procedure call. Unfortunately, JavaScript doesn’t offer built-in reflection capabilities to retrieve parameters dynamically. As a result, the only viable approach we found is to perform <strong>static analysis</strong> of the code.</p><p>In this context, parameters are considered required unless a default value is provided. This allows us to properly handle the mapping and validation of arguments when making remote procedure calls.</p><p>With this approach, we are now ready to generate efficient, distributable bundles. Scematically, the full process looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*UyeBOkVXuAZKdjYQ" /></figure><p>And here is the final code of the generated segment module, before bundling:</p><pre>// reporting.segment.js<br><br>import {Segment, Procedure, Implementation, Version, NamedParameter} from &quot;jitar&quot;;<br>import $1 from &quot;./reporting/getMonthReport.reporting.js&quot;;<br>import $2 from &quot;./reporting/formatMonthReport.reporting.js&quot;;<br><br>export default new Segment(&quot;reporting&quot;)<br>  .addProcedure(new Procedure(&quot;reporting/getMonthReport&quot;)<br>    .addImplementation(new Implementation(new Version(0, 0, 0), &quot;public&quot;,<br>      [new NamedParameter(&quot;year&quot;, false), new NamedParameter(&quot;month&quot;, false)], $1))<br>  )<br>  .addProcedure(new Procedure(&quot;reporting/formatMonthReport&quot;)<br>    .addImplementation(new Implementation(new Version(0, 0, 0), &quot;private&quot;,<br>      [new NamedParameter(&quot;data&quot;, false)], $2))<br>  );</pre><p>Before creating the segment model, all functions and classes need to be imported. It’s crucial to ensure that each has a unique name to prevent naming conflicts, especially for <strong>named imports</strong>. Although I didn’t use named imports in the example, we did implement support for them.</p><p>It’s also worth noting that all implementations default to version zero if no version is specified in the configuration. This versioning system allows us to track and manage updates to the functions and services in the segment.</p><p>Once the segment bundles are prepared, they are ready to be loaded and executed. This sets the stage for the third part: Running applications, where we’ll dive into the execution process and how everything comes together.</p><p>Thank you for taking the time to read this article. I truly hope you’ve enjoyed its contents and will consider reading all parts.</p><p>If you have any questions or feedback, I would greatly appreciate it if you left a comment or reached out to me on Discord: <a href="https://discord.gg/Bqwy8azp5R">https://discord.gg/Bqwy8azp5R</a></p><p>The Jitar project and its source code can be found on GitHub: <a href="https://github.com/MaskingTechnology/jitar">https://github.com/MaskingTechnology/jitar</a></p><p>An example project that fully leverages Jitar’s features is available here: <a href="https://github.com/MaskingTechnology/comify">https://github.com/MaskingTechnology/comify</a></p><p>Thanks again for being here, take care!</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=321762404778" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778">The Anatomy of a Distributed JavaScript Runtime | Part II — Splitting applications</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Anatomy of a Distributed JavaScript Runtime | Part I — Motivation and Goals]]></title>
            <link>https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/4d550f1f5bbe</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Thu, 10 Jul 2025 09:19:31 GMT</pubDate>
            <atom:updated>2025-08-12T08:45:05.229Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Anatomy of a Distributed JavaScript Runtime | Part I — Motivation and Goals</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*jLXU9IJJdsiQSiKPGKXJjg.png" /><figcaption>The scalpel is eager, the runtime is too (image by author)</figcaption></figure><p>In this article series, I’ll share how monolithic JavaScript (and TypeScript) applications can be split into distributed (micro)services with just configuration. We’ll explore the technical mechanics of this transformation and the principles for designing applications that embrace this duality.</p><p>The runtime we’ll be dissecting is Jitar. It’s fully open source, and you’ll find a link to the GitHub repository at the bottom of this article.</p><p>The series is divided into the following parts:</p><p><strong>Part I — Motivation and goals</strong><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-ii-321762404778">Part II — Splitting applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iii-3400d66c15cc">Part III — Running applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-iv-distributing-applications-7e9e9b7df54f">Part IV — Distributing applications</a><br><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-v-consolidation-and-conclusions-e84b04148f54">Part V — Consolidation and conclusions</a></p><p>If you’re only interested in the technical aspects, you can skip the first and last part. However, I recommend reading at least the first part to better understand the decisions made in the later sections.</p><h3>Part I — Motivation and Goals</h3><p>There are countless technologies available for building robust and resilient distributed applications. Creating a solution in this field takes a lot of time, effort, and deep expertise. So why should anyone take on this challenge? In this part, you’ll find the answers.</p><p>If you’ve read some of my earlier articles, you might already be familiar with parts of the story. This article ties them together to make it a whole. But before diving in, let me briefly introduce myself and the rest of the team.</p><h3>The team</h3><p>We’re currently a small, multi-disciplined team:</p><ol><li>A <strong>full-stack developer and architect</strong> with 20+ years of experience (that’s me)</li><li>A <strong>low-code developer and architec</strong>t with 15 years of experience (my business partner)</li><li>An <strong>integration specialist</strong> with 40+ years of experience (former colleague, now contributor)</li></ol><p>We’ve all worked on large-scale systems, and with our combined knowledge and experience, we genuinely believe we can pull this off. And since we’re all deeply familiar with Java… it only makes sense that we’re building a JavaScript runtime, right? No worries, I’ll clear this up later.</p><p>It’s also worth noting that we all come from the same consultancy-focused company, which is sponsoring most of the development work. There’s no plan to monetize the runtime. The value comes from showcasing our expertise to potential clients and speeding up internal product development.</p><p>The project is open to contributions, so if that sounds like something you’d want to be part of, come build with us. 😉</p><h3>Our motivation</h3><p>In the software industry, dealing with continuous change is one of the biggest challenges faced by development teams. Since we can only design for today, there’s a lot of uncertainty in the design decisions we have to make. This often leads to refactoring when those decisions don’t hold up over time.</p><h4>Architectural uncertainty</h4><p>To explain the impact of change, we often use the LEGO analogy to describe how we build our applications. In this analogy, the bottom plate represents the architecture, and the components are the stacked blocks. Typically, we use three layers of blocks to represent the data, business, and presentation logic (from bottom to top).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/0*qiMYGiWiyKKy4WKv" /></figure><p>With this setup, it’s easy to understand that if only the presentation layer at the top needs modification, there’s little impact since nothing else depends on it. But if the data layer changes, it could require breaking down and rebuilding large parts of the structure. And if the change impacts the architecture (the bottom plate), it could become an insurmountable problem. This is one of my biggest fears as an architect.</p><p>It turned out I wasn’t the only one with this fear. In many cases I’ve seen, it has been used as an argument for adopting microservice architecture, even when a monolithic architecture might be a better fit. Although this remains a common discussion in many organizations today, the <strong>modular monolithic architecture</strong> movement seems to be gaining more ground every day. And for good reasons.</p><h4>Modular architecture</h4><p>When done right, modular monolithic architecture is essentially a non-distributed version of microservice architecture. Services become modules that can be built and tested independently using modern tools like monorepos. The key difference is that it produces a single deployable unit instead of many, avoiding much of the complexity inherent in microservices. When needed, modules can still be refactored into services for reasons such as deployability or fault tolerance.</p><p>In our experience, architectural uncertainty is bi-directional. By that, we mean changes sometimes need to be undone. For example, when requirements don’t pan out as expected. I once refactored a crucial part of an application into a service for fault tolerance, based on the needs of a promising new client. But in the end, they never used the application and eventually stopped paying. This left us with additional cloud costs and maintenance overhead, ultimately forcing us to reverse the refactoring. That hurt.</p><p>A more recent and widely discussed example is Amazon Prime’s 90% infrastructure cost reduction after moving its monitoring service back to a monolith. In that light, we believe we’ll see more of these back-and-forth shifts in architecture, especially in today’s fast-paced digital landscape, where modern cloud platforms and AI-assisted development accelerate change.</p><p>And that brings us to the motivation for building our own runtime.</p><h4>Separation of concerns</h4><p>To make scalable applications more cost-efficient and future-proof, we believe architectural adaptability is essential. Not in the sense of making refactoring easier, but in eliminating the need for refactoring altogether.</p><p>When designing an application, we currently have to account for the deployment model. We’ve found this to be the key bottleneck limiting the adaptability we’re aiming for, eventually leading us to the following insight.</p><blockquote><strong>The deployment model should never dictate the application architecture.</strong></blockquote><p>Since development and deployment are fundamentally different concerns, it’s actually quite odd that they are so tightly coupled. That’s why we set out to separate the two:</p><ol><li><strong>Development model</strong> — the logical decomposition into modules and components;</li><li><strong>Deployment model</strong> — the physical decomposition into deployable units (e.g., services).</li></ol><p>This approach allows an application to be logically divided across teams by business capability, subdomain, or other criteria, while being physically deployed based on factors like performance, security, and recoverability.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/0*kQN_X5tAPTI622xQ" /></figure><p>To achieve full adaptability, we need a dynamic deployment model that can evolve with its context. For example, when a part of the application experiences high load, we want to isolate it and load balance it across multiple instances. Then, when the load decreases, we want to reintegrate it back into the monolith.</p><p>To the best of our knowledge, no existing solution could realize this vision. So, after careful consideration, we took the leap and embarked on the journey of building our own.</p><h3>Main design goals</h3><p>At its core, our solution is responsible for splitting applications at the component level into distributable bundles and automating end-to-end communication.</p><p>Surrounding that core, there’s a lot of ground to cover. As with any solution, it’s essential to define clear goals and boundaries. Here’s what we settled on.</p><h4>#1: Not a framework</h4><p>That’s right, we deliberately avoided building a framework. It may be the harder path, but we truly believe it’s the most important decision we’ve made. Here’s why.</p><p>Frameworks are heavy dependencies that provide opinionated solutions and rely heavily on abstractions. To support splitting applications at the component level, our abstractions would need to reach into every part of the codebase. This creates a significant risk: a breaking change in the framework could ripple through the entire application.</p><p>Instead, by working at the runtime level, we avoid embedding ourselves directly into the application code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/907/0*xZVgQbrrmv1JgoeJ" /></figure><p>Breaking changes at the runtime level are isolated to their configuration files, making it much safer and easier for us to manage.</p><h4>#2: Full-stack solution</h4><p>Coming from a full-stack background, I’ve always valued a seamless connection between frontend and backend. Since automating end-to-end communication of components is central to the runtime, we saw an opportunity to include the frontend, and we took it.</p><p>Looking back, we don’t regret that decision, as it significantly simplifies the development of scalable web applications. However, it also had a major impact on our development process. If we had to do it all over again, we’d probably hold off on that part until the rest of the runtime was more mature.</p><h4>#3: Simplified development</h4><p>In a microservice architecture, most services depend on at least one other service. During development, this typically means either spinning up those dependencies locally or mocking them. Mocking is often the better option, especially when developing contract-based, but maintaining those contracts and mocks still introduces complexity and overhead.</p><p>Ideally, an application could run as a monolith during development and be deployed as microservices in production, without concerns about differing behavior between the two.</p><p>That’s why we wanted to support multiple deployment strategies across all environments: local development, testing, acceptance, and production. This flexibility not only simplifies development and testing, but also makes it easier to scale or spin out new instances, for example, in multi-tenant scenarios.</p><h4>#4: Simplified operations</h4><p>A microservice architecture requires configuring and maintaining a range of additional services for communication, fault tolerance, monitoring, and more. To simplify this, we chose to integrate these capabilities directly into the runtime, creating a true one-stop-shop solution.</p><p>We believe this is key to making applications more flexible and adaptable. When the context changes and we need to act fast, we don’t want to spend time selecting, configuring, and testing an entire stack of separate tools.</p><h4>#5: Easy integrations</h4><p>Applications rarely live in isolation. In most cases, they’re part of a larger system or ecosystem. That’s why it’s important to us that applications can integrate easily with other services and third-party systems.</p><p>To support this, we aim to support multiple communication protocols such as HTTP, gRPC, and more. Regardless of the protocol, communication will always follow an RPC-style model. As a result, REST over HTTP is not supported (by design).</p><h4>#6: Extensible architecture</h4><p>One of our key concerns with automating end-to-end communication was the potential loss of control over essentials like authentication, authorization, logging, and error handling. To address this, we considered two options: either bake everything into the runtime or design it to be extensible through plugins. Since there’s no one-size-fits-all solution for these kinds of concerns, we chose the latter.</p><p>To support this, we introduced two common types of plugins:</p><ol><li><strong>Middleware</strong> — for handling things like authentication, logging, and custom headers;</li><li><strong>Health checks</strong> — to improve reliability and maintainability.</li></ol><p>At first glance, this might seem like a straightforward design decision, but it wasn’t. It challenged our very first design goal: not a framework. Fortunately, both plugin types live outside the application code, even though they do introduce files that depend on the runtime.</p><p>In the end, it’s all about trade-offs, isn’t it?</p><h3>Technology choices</h3><p>With our goals defined, it was time to choose a technology stack. Since we’re building a full-stack solution, there was really only one logical choice: JavaScript.</p><p>And if you say JavaScript, you’re essentially saying Node.js. It’s the most widely used runtime, and most of its competitors are compatible with it, making it the safest bet for now.</p><p>Before we started, several solutions already aimed to automate end-to-end communication. But all of them were frameworks, focused narrowly on frontend–backend interaction, and ultimately too limited to serve as a solid foundation for what we envisioned.</p><p>Since then, not much has changed. There are more options, but the core limitations remain. The only notable exception was Google’s <strong>Service Weaver</strong>, which shared a similar vision, but was built as a backend framework for Go. Interestingly, it was released about four months after I published my first article on our solution, and it was discontinued a few months ago.</p><p>So, we decided to start from scratch and build only what we needed, as we needed it. The only framework we currently use is Express.js, and only for HTTP protocol support. Its footprint is minimal enough that we may eventually replace it with something even lighter.</p><p>Lastly, coming from a Java background, we’re used to strong typing. That’s why we chose TypeScript, but with a twist. We use it strictly for typing: no enums, no decorators, and no TypeScript-specific constructs. Just types.</p><p>With that, we’ve reached the end of this part. Next up: Splitting Applications, where we’ll explore the mechanics of breaking a monolith into distributable bundles.</p><p>Thank you for taking the time to read this article. I truly hope you’ve enjoyed its contents and will consider reading all parts.</p><p>If you have any questions or feedback, I would greatly appreciate it if you left a comment or reached out to me on Discord: <a href="https://discord.gg/Bqwy8azp5R">https://discord.gg/Bqwy8azp5R</a></p><p>The Jitar project and its source code can be found on GitHub: <a href="https://github.com/MaskingTechnology/jitar">https://github.com/MaskingTechnology/jitar</a></p><p>An example project that fully leverages Jitar’s features is available here: <a href="https://github.com/MaskingTechnology/comify">https://github.com/MaskingTechnology/comify</a></p><p>Thanks again for being here, take care!</p><h3>Thank you for being a part of the community</h3><p><em>Before you go:</em></p><ul><li>Be sure to <strong>clap</strong> and <strong>follow</strong> the writer ️👏<strong>️️</strong></li><li>Follow us: <a href="https://x.com/inPlainEngHQ"><strong>X</strong></a> | <a href="https://www.linkedin.com/company/inplainenglish/"><strong>LinkedIn</strong></a> | <a href="https://www.youtube.com/@InPlainEnglish"><strong>YouTube</strong></a> | <a href="https://newsletter.plainenglish.io/"><strong>Newsletter</strong></a> | <a href="https://open.spotify.com/show/7qxylRWKhvZwMz2WuEoua0"><strong>Podcast</strong></a> | <a href="https://twitch.tv/inplainenglish"><strong>Twitch</strong></a></li><li><a href="https://differ.blog/"><strong>Start your own free AI-powered blog on Differ</strong></a> 🚀</li><li><a href="https://discord.gg/in-plain-english-709094664682340443"><strong>Join our content creators community on Discord</strong></a> 🧑🏻‍💻</li><li>For more content, visit <a href="https://plainenglish.io/"><strong>plainenglish.io</strong></a> + <a href="https://stackademic.com/"><strong>stackademic.com</strong></a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4d550f1f5bbe" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/the-anatomy-of-a-distributed-javascript-runtime-part-i-4d550f1f5bbe">The Anatomy of a Distributed JavaScript Runtime | Part I — Motivation and Goals</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strategy Matters: Embracing Versatile Development in Software Projects]]></title>
            <link>https://itnext.io/strategy-matters-embracing-versatile-development-in-software-projects-322be6ed5c27?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/322be6ed5c27</guid>
            <category><![CDATA[agile-development]]></category>
            <category><![CDATA[waterfall-model]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[iterative-development]]></category>
            <category><![CDATA[software-process]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Mon, 08 Jan 2024 18:22:39 GMT</pubDate>
            <atom:updated>2024-01-09T10:32:43.846Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QdPAbkS7jQ-w5cFq" /><figcaption>Photo by <a href="https://unsplash.com/@jeffreyp?utm_source=medium&amp;utm_medium=referral">Jeffrey Workman</a> on <a href="https://unsplash.com/photos/YvkH8R1zoQM?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Let me start with taking away a common misconception. There’s no such thing as a good or bad software development strategy. But there is such a thing as a bad choice. Almost every organization I know uses Scrum these days. Many of them use it because everybody else does, not because they’ve weighed the alternatives. For me, this is the best explanation why terms like “SINO” (Scrum In Name Only) and “WaterScrum” (doing Waterfall in Scrum) exist. Like anything, Scrum is not a silver bullet.</p><p>It’s common sense that you shouldn’t do things because everybody else is doing it. But in this case, it’s not that simple. Scrum has become so big, that doing something else feels like turning your back against the industry. Although this might not feel as the right thing to do, it can be very beneficial. So be strong, because this article is for the brave.</p><p>Before this article has Scrum written all over it, I want to leave it here. But, I can’t do that before aligning with you first. Scrum is an Agile framework. Agile is an approach, providing a mindset. Besides Agile, there are more options that will be discussed later on. A framework provides practices and processes fitting a particular mindset. Besides frameworks, there are also methodologies. In contrast to a methodology, a framework has some open end for you to close. This makes a framework more flexible and accessible, but you have to know what you’re doing in order to make it effective.</p><p>Time to talk strategy. A strategy defines the plan for managing the project. It defines the approach, practices and processes. The simplest way is using a methodology because it already defines everything you need. When using a framework, all open ends need to be closed to complete the strategy. But what makes a good strategy? I use the following two basic rules.</p><p>First, the strategy must align with the business and the development team. This is a simple rule in concept, but not in practice. In many cases I’ve seen, the business wants predictability and development wants adaptability (WaterScrum, anyone?). It’s important to have a mutual understanding in order to come to a strategy together that works.</p><p>Second, the strategy must align with the project context. This context defines the external dependencies, application scope, milestones, etc.. But only for as far as known at this point of time. It’s important to address unknowns and uncertainties so they can be taken into account in the strategy.</p><p>Defining a strategy starts with picking an approach. The simplest of all is the Waterfall approach, a phased model from analysis till maintenance. Every phase has to be completed before going to the next. It requires a clear and fixed scope at forehand, because it leaves little room for corrections. The later a flaw is discovered in the process, the bigger the impact.</p><p>If the scope has a few unknowns or uncertainties, an iterative approach might be a better choice. In this approach applications are developed and delivered in smaller chunks, helping to detect flaws earlier in the development to lessen the impact of any correction. The same process is repeated for the development of each chunk, making it iterative.</p><p>For scopes with a lot of unknowns and uncertainties, a more flexible approach is required. This brings us to the last, already named option: Agile. The key characteristics of this approach include collaboration and short feedback loops. Applications are developed and delivered in (very) small pieces, enabling making adjustments on the go and keeping the impact to a minimum.</p><p>In essence, these approaches go from delivering a complete solution and catching feedback late, to delivering small increments and catching feedback early. Agile is often considered the safest choice because it’s the most flexible. Although this is true, it comes with a cost. Agile places high pressure on the involvement of people, which inevitably means that they have less time for other tasks. In the wrong context, this could result in significant overhead.</p><p>Picking the right approach has everything to do with predictability. In a high predictability context, the scope can be made clear and fixed. Personally, I’ve never been in such a context. In my experience, there are always unknowns and uncertainties. So, does that mean that I always have to go to Agile? Yes and no.</p><p>Any context needs to have knowns and certainties in order to be feasible. This means we can split the context in predictable and unpredictable parts, allowing a hybrid development approach. The predictable parts can be developed using the Waterfall approach, the rest using Agile. This hybrid approach is known as the “Agile Waterfall”.</p><p>I’ve been using the Agile Waterfall approach off and on for a few years now. And I can tell you this: it’s not a silver bullet either. Managing a project using two approaches side by side isn’t easy. Especially when working with external clients that require frequent progress updates. On the other hand, it has been successful in reducing the overhead and making the development more cost-efficient.</p><p>When defining a development strategy, picking an approach is the most important step. Next, a framework or methodology needs to be chosen that defines the practices and processes. There are a lot of options out there, and I want to encourage you to look beyond Scrum. It could just be that one of the others fits your context better.</p><p>With that, I’ve come to the end of this article. But I can’t close off without these last words: No matter how good the strategy is, there’s one ingredient that can ruin it all if missing: discipline. Without discipline, the strategy becomes ad hoc. Which in all cases I’ve seen has led to an uncontrollably chaos.</p><p>Have you encountered unique challenges or successes in your software development projects? Share your experiences or thoughts in the comments below! I’m excited to continue the conversation with you.</p><p>A big thanks for reading! I hope you’ve enjoyed it, and maybe learned something. I’m always open to feedback and happy to answer any question.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=322be6ed5c27" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/strategy-matters-embracing-versatile-development-in-software-projects-322be6ed5c27">Strategy Matters: Embracing Versatile Development in Software Projects</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Monoliths To Microservices — And Beyond]]></title>
            <link>https://medium.com/better-programming/from-monoliths-to-microservices-and-beyond-5f1e639d5b4f?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f1e639d5b4f</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[modularization]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[micoservices]]></category>
            <category><![CDATA[monolith]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 21:53:29 GMT</pubDate>
            <atom:updated>2023-08-31T21:53:29.034Z</atom:updated>
            <content:encoded><![CDATA[<h3>From Monoliths To Microservices — And Beyond</h3><h4>Now that the hype around microservices is ending, what lessons have we learned? And what’s next?</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9-VuW0suzGEJimj2tePGrg.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@scw1217?utm_source=medium&amp;utm_medium=referral">Suzanne D. Williams</a> on <a href="https://unsplash.com/photos/VMKBFR6r_jg?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The microservice architecture has reigned for many years. In its era, we’ve experienced the good, the bad, and the ugly. In this article, we’ll look at the lessons learned and explore new developments in the field of building future-proof applications.</p><p>This won’t be a history lesson but a practical journey in the present time. We’ll look at the struggles of a development team facing rapid growth and uncertainties. Monoliths have a bad reputation, and microservices come with a cost. Migrating from one to the other mostly ends up in a nightmare. What options do they have? Let’s dive in.</p><p>Suppose we need to build an application for a starting company that sells cars using a unique formula. The MVP requirements are simple: keep a list of customers and manage orders. There’s limited time and money for the application’s development.</p><p>In this context, the monolithic architecture seems to be the best option because it’s the simplest and cheapest way to build an application. All features and components are placed in a single codebase, so there’s only one thing to worry about. It’s easy to develop, test, and deploy. Both management and the development team unanimously decided to go for this option.</p><p>As time passes, the application gets frequently updated with new features, and the development team slowly grows. Business is doing great and is ready to expand its services with another new formula, but this time for renting cars. Of course, the application should fully support this new service. It’s up to the development team to make this happen. They have gathered to discuss the impact of the application and how to implement the new requirements in a maintainable fashion.</p><p>The monolithic architecture is simple but doesn’t scale well. Once the number of features grows and more developers are needed to keep up the pace, it becomes harder to avoid creating a <a href="https://en.wikipedia.org/wiki/Anti-pattern">Big Ball of Mud</a>. Also, growing applications take more and more time to complete the build, test, and deploy. No matter the change, even if it’s a simple one, it has to go through the full process. CI/CD becomes a nightmare.</p><p>The development team wants to avoid this. But what are the options? Well… as many wise people would say, it depends. In any case, the application needs to be broken up into smaller, independent pieces. Each piece can then be developed, tested, and deployed by a separate team. Developers only have to focus on their piece of the puzzle, making it more manageable. Great stuff.</p><p>The biggest question is, however, how small the pieces need to be. Its answer fully depends on how much the sales and rental services overlap in terms of features and information. If there’s no overlap, the team can develop independent applications for both services. Besides having two codebases to worry about, there’s no additional complexity.</p><p>When there’s a little overlap (e.g., customer management), it’s still valuable to develop independent applications. A <a href="https://en.wikipedia.org/wiki/Service-oriented_architecture">service-oriented architecture</a> (SOA) will probably suffice here for coupling the applications. This architecture type allows (enterprise) organizations to compose a single system of multiple applications.</p><p>In this architecture style, applications are called (coarse-grained) services. For the implementation, the team can choose to make the rental service use the existing customer management implementation of the sales service. Alternatively, they can split off and move the customer management to its own service for better reusability.</p><p>Besides the two or three codebases, there’s also the interaction (coupling) to worry about. This makes it a bit more complex to set up and maintain the application. More on this later.</p><p>In case of a lot of overlap (e.g., users, customers, cars, orders, billing, etc.), the <a href="https://en.wikipedia.org/wiki/Microservices">microservice architecture</a> is likely a better fit. This architecture style is a specific implementation of an SOA aimed at maximizing flexibility and reusability by using smaller (fine-grained) services and allows for composing an application of feature-oriented services.</p><p>For the implementation, the team can implement independent services for the user, customer, sales and rental features, and more. Besides the many codebases and interactions, there’s also the team division (responsibilities) to worry about. This adds a lot of complexity to the setup and maintenance of the application.</p><p>A lot of the complexity comes with a characteristic bound to any service-oriented architecture: it’s a distributed system. This type of system is not known for being simple or cheap. It brings a lot of infrastructure overhead and additional services required for running the individual services and providing the interaction between them.</p><p>Also, managing data transactions between services is a tough nut to crack. The math is simple: more services equal more overhead and complexity.</p><p>The interaction between services can be organized in several ways. The simplest option is “orchestration,” where a process gets executed (conducted) step-by-step in a single thread by one of the services or a workflow engine. This centralizes the control of services, making it easy to build, maintain, and debug. On the other hand, it introduces a single point of failure and adds coupling between the services. When done wrong, the independence of services is broken, and a Big Ball of Mud lurks.</p><p>An alternative that overcomes these risks is “choreography.” It decentralizes the control of services by applying an event-driven approach. In this approach, each service is making its own decisions on when (not) to act. Like dancers, they listen and react to their cue of the music (event stream). This strongly decouples the services, making the application highly adaptable. Events can be stored for later consumption, making processes repeatable and resumable.</p><p>This makes the application highly fault-tolerant. On the other hand, the strong decoupling makes the application harder to build, debug, understand, and monitor. When not implemented and documented properly, figuring out what’s going on becomes nearly impossible.</p><p>With all options explored, the team can start weighing them to come to a well-thought-out solution. This solution should be future-proof and affordable. Keeping the monolith isn’t an option because it doesn’t scale well enough. An event-driven microservices approach does, but it is the most complex and expensive option.</p><p>So, the team wants to find the most cost-effective solution somewhere in between. They know that finding the right spot heavily depends on the business needs (overlap), and these needs might not be the same tomorrow. But how do you design for a spot that’s constantly moving?</p><p>In the ideal world, applications can start as a monolith and painlessly progress to a service architecture. But the world hasn’t been ideal, and this progression has been a big problem for many organizations. Breaking up a monolith involved a lot of heavy refactoring and, in more than a few cases, a complete rewrite of the application.</p><p>There are multiple causes at the root of the problem. For example, programming languages lacked support for strong modularization, allowing us to create a Big Ball of Mud. Also, architectures encouraged using a technical decomposition (e.g., MVC, layered), which is very different from a typical service decomposition (feature-oriented). Both make unraveling the features and translating them into services very hard. Adding multi-team development and high pressure to the mix completes the disaster recipe.</p><p>Luckily, time hasn’t been standing still, and technology has evolved. Languages have adopted support for strong modularization (e.g., <a href="https://www.oracle.com/corporate/features/understanding-java-9-modules.html">Java modes</a>, <a href="https://hacks.mozilla.org/2018/03/es-modules-a-cartoon-deep-dive/">ES modules</a>), architecture started to encourage feature-based decomposition (e.g., <a href="https://awesome-architecture.com/vertical-slice-architecture/">vertical slicing</a>), and new tooling emerged to improve multi-team development (e.g., monorepos). This strong combination allows us to build evolvable modular monoliths.</p><p>In a <a href="https://awesome-architecture.com/modular-monolith/">modular monolithic architecture</a>, an application comprises small, independent feature-oriented modules. This might sound familiar because it’s almost a complete analogy of the microservice architecture. The only difference is that local modules are used instead of distributed services.</p><p>Simply put, it’s a non-distributed version of the microservice architecture. It has all the flexibility and reusability advantages but without the complexity of a distributed system. Because both architectural styles are so similar, the same decomposition and interaction strategies can be used. Meaning that, when done properly, a module can be transformed into a service and the other way around.</p><p>Now, let’s go back to the team’s question on how to design for the future while minimizing costs. By modularizing the application, they can break the big application into small independent pieces (services) while keeping a monolithic architecture for as long as possible.</p><p>Modules can be split off and transformed into services when required for the right reasons, like independent deployments, fault tolerance, etc. They can be split off per group (SOA), one by one (microservices), or a mix of both. This suits the team’s needs well because they’ve already concluded that they don’t need a service architecture.</p><p>Transforming a module into a service is fairly easy because its internal structure doesn’t change. But there’s still quite some work involved to make it happen. Like setting up a new project, end-points (or subscribers), requests (or publishers), operations, etc.</p><p>Depending on the number of splits, this still can lead to a lot of overhead. Also, the number of codebases to worry about starts growing again. This concerns the team because the business isn’t sitting still, and new ideas pop up weekly. The team finds it very likely that they need to do a lot of split-offs in the short term. So, the question has been raised again if they won’t be better off starting with a microservice architecture right away.</p><p>Answering the team’s question is a difficult one. Although the modular monolith makes the architecture more agile, the transformation process to a service architecture can still be a hurdle. They can go for the modular monolith if they can overcome this hurdle. Otherwise, they need to go for microservices to play safe.</p><p>Overcoming this hurdle requires a solution that separates the development model from the deployment model in a way that the application can be built as a modular monolith and deployed as a service without any development effort. The only problem is that such a solution doesn’t exist, leaving the team behind with a hard choice.</p><p>I have often struggled with this decision-making process, always striving to find the best possible solution. I adopted non-technical decomposition strategies and monorepos quite early on and attempted to maintain a strong modularization pattern before languages even began to adopt it. But I’ve learned that this wasn’t enough, and it motivated me to do something about it.</p><p>For the past few years, I’ve been developing a distributed runtime solution that allows users to build a monolith and deploy it as services. It refracts the monolith into services at the runtime level, like a prism does with light.</p><p>The services are defined by configuration, and the communication between the services is fully automated. Although I started in Java, I quickly found that a backend-only solution wasn’t enough because I mostly build full-stack applications. So, I’ve switched to TypeScript and extended the capabilities to include the frontend. This enabled me to combine the frontend and backend in a single code base without worrying about the end-to-end communication and (future) deployment needs.</p><p>The project is called Jitar (abbreviation of Just-In-Time-ArchitectuRe) and is fully open source. Although it’s still a work in progress, it’s already fully functional for most applications. More information can be found on its <a href="https://jitar.dev/">website</a> and <a href="https://github.com/MaskingTechnology/jitar">GitHub</a>. I’ve also written <a href="https://betterprogramming.pub/how-i-split-a-monolith-into-microservices-without-refactoring-5d76924c34c2">an article about my view on just-in-time architecture</a>. It overlaps this article, but it is written from my personal experience.</p><p>With this, the article has come to an end. A big thanks for reading. I hope you’ve enjoyed it and maybe learned something. I’m always open to feedback, and I’m happy to answer any questions.</p><blockquote>Bonus: Technology has also evolved on the infrastructure level. Service mashes, serverless and edge computing have emerged to help bring down the complexity of distributed systems. This is outside the scope of this article, but it’s good to know that if an application evolves into services, it has become less painful. Cheers!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f1e639d5b4f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/from-monoliths-to-microservices-and-beyond-5f1e639d5b4f">From Monoliths To Microservices — And Beyond</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</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 Split a Monolith Into Microservices with Jitar]]></title>
            <link>https://medium.com/better-programming/how-to-split-a-monolith-into-microservices-with-jitar-95caf6f81e08?source=rss-ec9f0e30558b------2</link>
            <guid isPermaLink="false">https://medium.com/p/95caf6f81e08</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Peter van Vliet]]></dc:creator>
            <pubDate>Wed, 21 Dec 2022 10:44:17 GMT</pubDate>
            <atom:updated>2022-12-21T18:08:10.607Z</atom:updated>
            <content:encoded><![CDATA[<h4>Learn how to use the Jitar runtime for transforming a monolith into microservices without refactoring</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g-ukQjh9rqHr6oOD0STJ0A.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@soulsana?utm_source=medium&amp;utm_medium=referral">SOULSANA</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In my <a href="https://betterprogramming.pub/how-i-split-a-monolith-into-microservices-without-refactoring-5d76924c34c2">previous article</a>, I wrote about my journey towards a just-in-time architectural style that enabled me to split up a monolith into microservices without refactoring. The key solution I found was a combination of automated API creation and a flexible segmentation strategy. This has led to the creation of <a href="https://github.com/MaskingTechnology/jitar">Jitar</a>, a distributable runtime for JavaScript (and TypeScript) applications.</p><p>In this article, I want to dive deeply into building a splittable monolith and split it into microservices using the Jitar runtime. We’ll use the small online store example from the previous article. I recommend reading the previous article if you haven’t done that yet, but it isn’t required. The application and transformation will be explained step by step so you can follow along. The final result is also available on <a href="https://github.com/petermasking/jitar-microservices">GitHub</a>.</p><p>Before starting, ensure you have<a href="https://nodejs.org/"> Node.js</a> version 18.7 or higher installed on your machine. I like to be type-safe, so I’ll use TypeScript for the example. Make sure you have version 4.4.2 or higher installed. I use <a href="https://code.visualstudio.com/">VS Code</a> as an editor, but feel free to use another. Also, I work on a MacBook. The commands in this article work on Mac OS and Linux. Ready, set, go!</p><h3>Step 1: Setup the Application</h3><p>Let’s take a closer look at the online store first. Although the company behind the store is small, it’s divided into four departments. Each with its own unique responsibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*9whKzicaB01ZMtFP_5JEew.png" /></figure><p>Our application will automate the order placement process with the following steps:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/897/1*VjbmlD29ygWM3rAM_z6Y8Q.png" /></figure><p>We need to create a new NPM project to set up the application.</p><pre>mkdir jitar-microservices<br>cd jitar-microservices<br>npm init</pre><p>I’ve entered my way through the initialization to use the default settings. Feel free to make other choices here. Jitar heavily depends on the ES module system. Node uses the CommonJS module system by default, so we need to change this in the package.json file by setting the type to module.</p><pre>{<br>    &quot;type&quot;: &quot;module&quot;,<br>    /* name, version, description, etc. */<br>}</pre><p>For setting up TypeScript, we need to add a configuration file. We can use the following command:</p><pre>touch tsconfig.json</pre><p>I use the following configuration:</p><pre>{<br>    &quot;compilerOptions&quot;:<br>    {<br>        &quot;target&quot;: &quot;esnext&quot;,<br>        &quot;module&quot;: &quot;es2022&quot;,<br>        &quot;rootDir&quot;: &quot;./src/&quot;,<br>        &quot;moduleResolution&quot;: &quot;node&quot;,<br>        &quot;outDir&quot;: &quot;./dist&quot;,<br>        &quot;removeComments&quot;: true,<br>        &quot;forceConsistentCasingInFileNames&quot;: true,<br>        &quot;strict&quot;: true,<br>        &quot;skipLibCheck&quot;: true<br>    },<br>    &quot;exclude&quot;: [&quot;cache&quot;, &quot;dist&quot;, &quot;node_modules&quot;]<br>  }</pre><p>Note that we need to make sure that the ES module system is used as an output format by the compiler.</p><p>Of course, we’ll also need a source folder for our code files.</p><pre>mkdir src</pre><p>Now we’re ready to identify and set up the application modules. To keep things simple, we’ll use the <a href="https://microservices.io/patterns/decomposition/decompose-by-business-capability.html">decomposition by business capability</a> for identifying the modules. In this case, we can translate each department into a module.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*2OeqIu8AAHfVpPQ6qujQpg.png" /></figure><p>To set up the basic application structure, we’ll create a separate subfolder per module in the source folder.</p><pre>cd src<br>mkdir order product inventory delivery</pre><p>Next, we can look at the implementation. I’ve created a sequence diagram to visualize the interaction between the modules. This always helps me with the translation to code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*ebENKfWt1rXkJRgYPxrZAg.png" /></figure><p>The diagram shows that the order module controls the process, meaning it has a strong relationship with the other modules. This is fine for smaller applications, but larger applications might benefit from a more decoupled approach.</p><p>Time to build the application. We’ll create a separate file for each component. This is not mandatory, but I think this is good practice because it avoids stepping on each other’s toes when working with multiple developers. We need two types of components: functional and data. Let’s create the files first.</p><pre>touch order/placeOrder.ts product/getProducts.ts product/Product.ts inventory/updateStock.ts order/createOrder.ts order/Order.ts delivery/planDelivery.ts delivery/Delivery.ts</pre><p>We’ll start with writing the main functional component, which is implementing the place order process. We’ll create a function for the implementation that calls the functions from the other modules.</p><pre>// src/order/placeOrder.ts<br>import { planDelivery } from &#39;../delivery/planDelivery.js&#39;;<br>import { updateStock } from &#39;../inventory/updateStock.js&#39;;<br>import { getProducts } from &#39;../product/getProducts.js&#39;;<br>import { createOrder } from &#39;./createOrder.js&#39;;<br><br>export async function placeOrder(productIds: string[], address: string): Promise&lt;string&gt;<br>{<br>    const products = await getProducts(productIds);<br>    await updateStock(productIds);<br><br>    const order = await createOrder(products);<br>    const delivery = await planDelivery(address);<br><br>    return `Your order #${order.id} with ${order.productCount} products `<br>         + `will be delivered to &quot;${delivery.address}&quot; on ${delivery.dateString}`;<br>}</pre><p>Note that this function and all other functions are async. This is an important addition that enables splitting the application.</p><p>Next, we’ll implement the other functions in the order they are called. Here’s the code:</p><pre>// src/product/getProducts.ts<br>import { Product } from &quot;./Product.js&quot;;<br><br>const products =<br>[<br>    new Product(&quot;1&quot;, &quot;Product 1&quot;),<br>    new Product(&quot;2&quot;, &quot;Product 2&quot;),<br>    new Product(&quot;3&quot;, &quot;Product 3&quot;),<br>    new Product(&quot;4&quot;, &quot;Product 4&quot;),<br>    new Product(&quot;5&quot;, &quot;Product 5&quot;)<br>]<br><br>export async function getProducts(productIds: string[]): Promise&lt;Product[]&gt;<br>{<br>    return products.filter(product =&gt; productIds.includes(product.id));<br>}</pre><p>For simplicity, I’ve replaced the database with a simple static list of products. For the implementation of a product, we’ll create a data component.</p><pre>// src/product/Product.ts<br>export class Product<br>{<br>    #id: string;<br>    #name: string;<br><br>    constructor(id: string, name: string)<br>    {<br>        this.#id = id;<br>        this.#name = name;<br>    }<br><br>    get id(): string { return this.#id; }<br><br>    get name(): string { return this.#name; }<br>}</pre><p>Note that I’ve used private fields to encapsulate the data. A product can’t be updated after its creation, making it immutable. This is common practice when working with distributed systems and is essential when breaking up and scaling an application without refactoring.</p><pre>// src/inventory/updateStock.ts<br>export async function updateStock(productIds: string[]): Promise&lt;void&gt;<br>{<br>    // Update stock per product<br>    // Throw error if product is out of stock<br>}</pre><p>I’ve added the update stock function for demonstration purposes but haven’t implemented it to keep an eye on the ball.</p><pre>// src/order/createOrder.ts<br>import { Product } from &#39;../product/Product.js&#39;;<br>import { Order } from &#39;./Order.js&#39;;<br><br>export async function createOrder(products: Product[]): Promise&lt;Order&gt;<br>{<br>    const id = Math.floor(Math.random() * 1000);<br><br>    return new Order(id, products);<br>}</pre><p>Also, here’s a simple implementation for order creation using a data component:</p><pre>// src/order/Order.ts<br>import { Product } from &#39;../product/Product.js&#39;;<br><br>export class Order<br>{<br>    #id: number;<br>    #products: Product[];<br><br>    constructor(id: number, products: Product[])<br>    {<br>        this.#id = id;<br>        this.#products = products;<br>    }<br><br>    get id(): number { return this.#id; }<br><br>    get products(): Product[] { return this.#products; }<br><br>    get productCount(): number { return this.#products.length; }<br>}</pre><p>Note that data components are transferred across the network automatically when an application is split up. Jitar can (de)serialize primary types (numbers, booleans, etc.) and complex objects (maps, dates, etc.). It supports private fields as long as the object can be reconstructed using the constructor or a setter. This is where other (de)serializers I’ve tried fail.</p><pre>// src/delivery/planDelivery.ts<br>import { Delivery } from &#39;./Delivery.js&#39;;<br><br>export async function planDelivery(address: string): Promise&lt;Delivery&gt;<br>{<br>    const today = new Date();<br>    const tomorrow = new Date();<br><br>    tomorrow.setDate(today.getDate() + 1);<br><br>    return new Delivery(address, tomorrow);<br>}</pre><p>We don’t want our customers to wait too long, so we always deliver the next day :-).</p><pre>// src/delivery/Delivery.ts<br>export class Delivery<br>{<br>    #address: string;<br>    #date: Date;<br><br>    constructor(address: string, date: Date)<br>    {<br>        this.#address = address;<br>        this.#date = date;<br>    }<br><br>    get address(): string { return this.#address; }<br><br>    get date(): Date { return this.#date; }<br><br>    get dateString(): string { return this.#date.toDateString(); }<br>}</pre><p>That’s it for the coding part. We have all the components needed to get our application up and running.</p><h3>Step 2: Run the Application</h3><p>To use Jitar as runtime, we add its Node.js server as a dependency.</p><pre>cd ..<br>npm install jitar-nodejs-server</pre><p>Because we start with a monolith, we only need a single backend segment that contains all four modules. The order module is our main module, so we can start with an order segment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/893/1*QgM-4aTAxpnYwVGqHWxAgA.png" /></figure><p>The placeOrder component needs to be exposed to the outside world to start the process. We can configure this in a <a href="https://docs.jitar.dev/04_basic_features#segmentation">segment configuration</a> file. When splitting the application, we will create more segment files. So we’ll create a separate folder for the segments first. This folder is placed in the project root folder.</p><pre>mkdir segments</pre><p>Now we can create the first segment file.</p><pre>touch segments/order.segment.json</pre><p>And add the following content:</p><pre>{<br>    &quot;./order/placeOrder.js&quot;: { &quot;placeOrder&quot;: { &quot;access&quot;: &quot;public&quot; } }<br>}</pre><p>The structure of a segment file is very similar to the JavaScript module system. In this case, we import placeOrder from ./order/placeOrder.js. Additionally, we set the access to public (private by default).</p><p>Note that the file path is relative to the source root of the application and that it imports the compiled JavaScript file (ends with .js). Jitar will import this component with the other components when loading the segment file.</p><p>To load the segment file, we need to configure Jitar. This is done by creating a new configuration file. But first, we’ll create a new folder because we’ll add more configurations later.</p><pre>mkdir jitar</pre><p>In this folder, we’ll create the first configuration file.</p><pre>touch jitar/standalone.json</pre><p>And add the following content:</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3000&quot;,<br>    &quot;standalone&quot;:<br>    {<br>        &quot;source&quot;: &quot;./dist&quot;,<br>        &quot;cache&quot;: &quot;./cache&quot;<br>    }<br>}</pre><p>This will configure a standalone setup, meaning that all required runtime services are bundled into a single Jitar server instance. It also tells Jitar to read the compiled JavaScript from the dist folder and write its cache to the cache folder.</p><p>To start Jitar, we need to create a bootstrapper in the source root folder. Here’s how to do that:</p><pre>touch src/jitar.ts</pre><p>And add the following content:</p><pre>import { startServer } from &#39;jitar-nodejs-server&#39;;<br><br>const moduleImporter = async (specifier: string) =&gt; import(specifier);<br><br>startServer(moduleImporter);</pre><p>With the start of a server, we need to provide a module importer that imports Node dependencies from the local application context instead of the Jitar context. Although the theory behind this is quite interesting, I’ll leave the details out for now.</p><p>Lastly, we need to add build and run scripts to the package.json file.</p><pre>{<br>    &quot;scripts&quot;: {<br>        &quot;build&quot;: &quot;tsc&quot;,<br>        &quot;standalone&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/standalone.json&quot;<br>  },<br>}</pre><p>And we’re all done and ready to go. We can test both scripts with the following commands:</p><pre>npm run build<br>npm run standalone</pre><p>After starting Jitar, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b0a78d1L3dICCUz_-u2prQ.png" /></figure><p>Note that our component has been registered successfully as an RPC entry. This means that we can call it using Jitar’s <a href="https://docs.jitar.dev/05_advanced_features#apis">PRC API</a>. I like to use HTTP files for creating and sharing test requests, so I’ll create one here too.</p><pre>touch request.http</pre><p>And add a test request.</p><pre>POST http://localhost:3000/rpc/order/placeOrder HTTP/1.1<br>content-type: application/json<br><br>{<br> &quot;productIds&quot;: [ &quot;1&quot;, &quot;3&quot;, &quot;5&quot; ],<br> &quot;address&quot;: &quot;My Secret Lair&quot;<br>}</pre><p>This will call the component using a POST request with the product ids and delivery address as the body. For the execution, I use the <a href="https://marketplace.visualstudio.com/items?itemName=humao.rest-client">REST Client</a> plugin for VS Code, but feel free to use any API tool you want.</p><p>If everything goes well, you should get a response like this:</p><pre>Your order #952 with 3 products will be delivered to &quot;My Secret Lair&quot; <br>on Thu Dec 22 2022</pre><p>That’s it for setting up Jitar and running the application. We now have everything we need to scale out.</p><h3>Step 3: Split the Application</h3><p>In the previous article, I used the introduction of a track and trace feature as an example reason for splitting off and load balancing the delivery module (I’m not the only one refreshing all the time, right?). It’s time to bring this into practice and transform the delivery module into a microservice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*XpB8FzeFKJckmLfH3aWoNA.png" /></figure><p>As the image shows, we need to create a separate segment for the delivery. Like the order segment, we need to add a segment file to the segments folder.</p><pre>touch segments/delivery.segment.json</pre><p>With the following content:</p><pre>{<br>    &quot;./delivery/planDelivery.js&quot;: { &quot;planDelivery&quot;: { &quot;access&quot;: &quot;public&quot; } }<br>}</pre><p>When restarting the application using the npm run standalone command, we should now see that also the planDelivery component has been registered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gx1uch9YsCtp4BKItoKCDA.png" /></figure><p>When starting Jitar as a standalone server, it will scan and register all *.segment.json files automatically and runs the application as a monolith. This works great when developing the application, but to split them in production, we need to configure Jitar differently.</p><p>Jitar comes with several <a href="https://docs.jitar.dev/03_runtime_services">runtime services</a> that are combined in the standalone mode. To split an application, we need to split the runtime. For this example, we can use the following setup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*NKktLK6aboF0s_KH3xLdmA.png" /></figure><p>This setup uses three different runtime services:</p><ol><li>A gateway for locating and load-balancing the components</li><li>A repository holding and providing the components</li><li>Two nodes for loading and running segment components</li></ol><p>Clients use the gateway as a central access point for the application. The gateway will forward the requests to the appropriate nodes. This should look very familiar if you have some experience with microservices. The repository is the only stranger in our midst, but don’t let it fool you. It plays the most important role of all.</p><p>When a node (worker) starts, it loads the components of the segments assigned to it. These components can import from other segments that do not run on this node. The repository is segment aware and knows exactly when to provide a remote implementation instead of the actual implementation.</p><p>We need to add a separate Jitar configuration per service to create this setup.</p><pre>touch jitar/repository.json jitar/gateway.json jitar/node-order.json jitar/node-delivery.json</pre><p>We’ll create them in starting order, beginning with the repository in the repository.json file.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:4000&quot;,<br>    &quot;repository&quot;:<br>    {<br>        &quot;source&quot;: &quot;./dist&quot;,<br>        &quot;cache&quot;: &quot;./cache&quot;<br>    }<br>}</pre><p>This setup looks very similar to the standalone configuration. That’s because the standalone mode handles the configuration of the other services.</p><p>Next, we’ll configure the gateway in the gateway.json file. We only need to set the repository location because the nodes will register themselves at the gateway.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3000&quot;,<br>    &quot;gateway&quot;:<br>    {<br>        &quot;repository&quot;: &quot;http://127.0.0.1:4000&quot;<br>    }<br>}</pre><p>Because we have two nodes, we need to configure them separately. The first will load and run the order segment configured in the node-order.json file.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3001&quot;,<br>    &quot;node&quot;:<br>    {<br>        &quot;repository&quot;: &quot;http://127.0.0.1:4000&quot;,<br>        &quot;gateway&quot;: &quot;http://127.0.0.1:3000&quot;,<br>        &quot;segments&quot;: [ &quot;order&quot; ]<br>    }<br>}</pre><p>The second node will load and run the delivery segment and is configured in the node-delivery.json file.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3002&quot;,<br>    &quot;node&quot;:<br>    {<br>        &quot;repository&quot;: &quot;http://127.0.0.1:4000&quot;,<br>        &quot;gateway&quot;: &quot;http://127.0.0.1:3000&quot;,<br>        &quot;segments&quot;: [ &quot;delivery&quot; ]<br>    }<br>}</pre><p>Note that each configuration uses a different port in the URL specification. This way, we can run the services on the same machine, which is convenient for now.</p><p>To start the services, we need to add scripts for them in the package.json file. In total, the scripts section looks like this:</p><pre>{<br>    &quot;scripts&quot;: {<br>        &quot;build&quot;: &quot;tsc&quot;,<br>        &quot;standalone&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/standalone.json&quot;,<br>        &quot;repository&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/repository.json&quot;,<br>        &quot;gateway&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/gateway.json&quot;,<br>        &quot;order&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/node-order.json&quot;,<br>        &quot;delivery&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/node-delivery.json&quot;<br>    },<br>}</pre><p>Time for testing. We haven’t touched the application, so we can skip the build step. We need to start each service from a separate terminal in the following order:</p><pre>npm run repository<br>npm run gateway<br>npm run order<br>npm run delivery</pre><p>With the start of the order node, we should see that it only registers the placeOrder component. The delivery node should only register the planDelivery component. If this is the case, then the segmentation works. We can check this by executing the request again. The gateway should tell us that it has run both components separately.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*70Ay3VhxgVu_KtBpOiE-aw.png" /></figure><p>Congratulations! You’ve just transformed a module into a service without refactoring.</p><p>From here, it’s easy to set up load balancing for the delivery service. We only need to start the delivery node for a second, third, … time. This doesn’t work on your local machine because the port is already in use. But we can copy the configuration to a new file.</p><pre>cp jitar/node-delivery.json jitar/node-delivery2.json</pre><p>And increase the port number in the URL in the node-delivery2.json file.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3003&quot;,<br>    &quot;node&quot;:<br>    {<br>        &quot;repository&quot;: &quot;http://127.0.0.1:4000&quot;,<br>        &quot;gateway&quot;: &quot;http://127.0.0.1:3000&quot;,<br>        &quot;segments&quot;: [ &quot;delivery&quot; ]<br>    }<br>}</pre><p>Don’t forget to add a script to the package.json file.</p><pre>&quot;delivery2&quot;: &quot;node --experimental-network-imports --experimental-fetch dist/jitar.js --config=jitar/node-delivery2.json&quot;</pre><p>Start the node, and see what happens when executing the request multiple times.</p><pre>npm run delivery2</pre><p>The gateway should now divide the load round robin over both delivery nodes.</p><p>In the current setup, the order segment contains the order, product, and inventory modules. Depending on your needs, creating a separate segment for each module and running them on the same node is possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*KU9gLxdsVExpe3sBEHJRhA.png" /></figure><p>This can be done by creating new segment files and adding the segments to the node configuration.</p><pre>{<br>    &quot;url&quot;: &quot;http://127.0.0.1:3001&quot;,<br>    &quot;node&quot;:<br>    {<br>        &quot;repository&quot;: &quot;http://127.0.0.1:4000&quot;,<br>        &quot;gateway&quot;: &quot;http://127.0.0.1:3000&quot;,<br>        &quot;segments&quot;: [ &quot;order&quot;, &quot;product&quot;, &quot;inventory&quot; ]<br>    }<br>}</pre><p>The effect will be the same as the current setup but adds a lot of flexibility to the deployability. If you’re developing a single-tenant application used by multiple customers, nodes can be configured to always fit the current (cloud) hosting needs. Running segments on a single node for as long as possible can help reduce operational costs.</p><h3>Conclusions</h3><p>Jitar makes a developer’s life easier by enabling splitting and distributing applications without refactoring. This doesn’t mean that building distributable applications have become super simple, but it adds a lot of flexibility that I haven’t found elsewhere. For example, applications can be developed as a monolith and deployed as microservices.</p><p>Although this article focuses on the backend, Jitar also allows splitting up the frontend. In an earlier article, I wrote about <a href="https://betterprogramming.pub/how-to-create-an-api-less-full-stack-application-with-react-and-jitar-602bcbabc66b">how to create a full-stack application with Jitar</a>. That article uses a single segment, but multiple segments can be created the same way we did in this article.</p><p>Before I sign off, I want to thank you for reading this article. I’m always open to feedback and happy to answer any question. In upcoming articles, I want to dive deeply into details like dealing with data(bases), authorization, etc. Suggestions/requests are welcome.</p><p><a href="https://betterprogramming.pub/how-i-split-a-monolith-into-microservices-without-refactoring-5d76924c34c2">How I Split a Monolith Into Microservices Without Refactoring</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95caf6f81e08" width="1" height="1" alt=""><hr><p><a href="https://medium.com/better-programming/how-to-split-a-monolith-into-microservices-with-jitar-95caf6f81e08">How To Split a Monolith Into Microservices with Jitar</a> was originally published in <a href="https://betterprogramming.pub/">Better Programming</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>