<?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 Zoe Lavena on Medium]]></title>
        <description><![CDATA[Stories by Zoe Lavena on Medium]]></description>
        <link>https://medium.com/@zoebrian.yl?source=rss-88e53ea71bc5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Zoe Lavena on Medium</title>
            <link>https://medium.com/@zoebrian.yl?source=rss-88e53ea71bc5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:07:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zoebrian.yl/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[Microservices]]></title>
            <link>https://medium.com/sw-d/microservices-60c5414064d4?source=rss-88e53ea71bc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/60c5414064d4</guid>
            <category><![CDATA[msf4j]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Zoe Lavena]]></dc:creator>
            <pubDate>Sat, 30 Mar 2019 19:13:23 GMT</pubDate>
            <atom:updated>2019-03-30T19:21:02.561Z</atom:updated>
            <content:encoded><![CDATA[<h3>Writing Microservices Using MSF4J</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*Ksk63978jtYFjorphepnBw.jpeg" /></figure><p>This blog post will be a step-by-step demonstration of writing microservices using MSF4J (MicroService Framework for Java). We are going to work on the ABC Diners Application which will be discuss briefly later in this post. This will also cover the steps that are involved when creating or migrating or transitioning to microservices.</p><h3>ABC Diners</h3><p>ABC Diners is a restaurant application. Aside from taking orders from their customers and viewing orders, they post recipes that customers will rate while waiting for their food.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/485/1*peZNXRtZjs_9ECGmk7zpYw.png" /></figure><p>We are going to pretend that ABC Diners has already a monolithic-based application, and they wanted to migrate to using microservice-based application for reasons that their business is growing and they have too much requests and data to handle.</p><h3>Three-Step Process</h3><p>Based on the book Microservice Patterns with Examples in Java by C. Richardson, there is a three-step process to migrating to microservices [1]:</p><ol><li><em>Define Business Capabilities</em></li><li><em>Define Services</em></li><li><em>Define APIs and Collaborations</em></li></ol><p><strong>Define Business Capabilities. </strong>In this step, we have to identify the functional requirements of the system. Given the brief description of the ABC Diners business, we can tell that in these are the possible functional requirements that the application requires, see Figure 1 below.</p><p><strong>Define Services</strong>. When defining the services, we have to group the functionalities that works in the same database.</p><p>In my previous post Microservices: Understanding the Background of Microservice Architecture, we define that a service is independent and has its own database structure. We have to lessen the joins for each databases as much as possible to enforce the major characteristics of microservices (modularity and loose coupling). Of course, there will be times that some services has to communicate or needs data from another service. If that is the case, we have to use the SAGA pattern to maintain data consistency.</p><p>For this demonstration, we are going to keep things simple. Given the list of functionalities on Figure 1, we can tell that add/delete/edit/rate recipe can be grouped into one service (and call it Recipe Service). View/Create orders can be grouped into another service (and call it Order Service), see Figure 2 below. Each of the ABC Diners application’s services has its own database named recipeDB and orderDB respectively.</p><p><strong>Define APIs and Collaborations</strong>. This step is easy and straightforward, we just have to change our functional requirements into methods (and/or add more methods if we are required to). For example, Add Recipe will be called addRecipe() method in our code, see the rest on Figure 3 below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*UyN0qy70alvgmaa7Mdioxw.jpeg" /></figure><h3>Requirements and Tools</h3><p>This demonstration requires at least a basic knowledge in the following areas:</p><ul><li><em>Java (more specifically working with Maven projects)</em></li><li><em>REST API (basic annotations such as @GET, @POST, @PUT, @DELETE)</em></li><li><em>JPA (used for mapping objects)</em></li><li><em>MySQL (used for writing the database script)</em></li></ul><p>Listed down are the tools that will be used in the demonstration:</p><ul><li>Eclipse, NetBeans (used for development)</li><li>MySQL Workbench (used for viewing the data)</li><li>Postman (used for constructing requests and reading responses)</li></ul><h3>Common Errors</h3><p>Before we move on, this post would like to introduce you to the common errors that might be encountered during the demonstration. We should be able to know how to migrate from and take actions to it.</p><ul><li><em>POM File Not Found</em></li><li><em>Persistence Exception</em></li><li><em>Project Unloadable</em></li><li><em>Cannot Connect to the Database</em></li><li><em>Cannot Import javax</em></li></ul><p><strong>POM File Not Found</strong>. A POM file is a file that contains information about the Maven project and its configurations. This happens when you try to create a Maven project in NetBeans — NetBeans assumes that you already have a POM file in the directory where the project will be built. In Eclipse, it creates one if a POM file does not exist in the directory. This is also the reason why Eclipse will be used in the first part of the demo, and later on will switch to NetBeans (we will have to use database).</p><p><strong>Persistence Exception</strong>. A persistence file is a configuration file in JPA. If this error occurs, the following steps has to be performed:</p><ul><li><em>Delete the existing persistence.xml file</em></li><li><em>Delete the existing models</em></li><li><em>Generate new models</em></li><li><em>Rename persistence name, if necessary</em></li></ul><p><strong>Project Unloadable</strong>. If this error occurs, right click on the project and select clean and build.</p><p><strong>Cannot Connect to the Database</strong>. If this error occurs, add the dependency jar file <em>com.mysql.jdbc</em>.</p><p><strong>Cannot Import javax</strong>. If this error occurs, add the dependency jar file <em>javax:javaee-web-api</em>.</p><h3>Demo 1: Hello World</h3><p>Step 1: Open <em>Eclipse IDE</em>, click on the <em>new</em> icon, expand <em>Maven</em>, select <em>Maven Project</em>. Click on <em>Next</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*FhhkUXHQQcEc_FWoHJ0ADQ.png" /></figure><p>Step 2: Select <em>Use default Workspace location</em>. Click on <em>Next.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/1*VcSA9R2pFX7GxT9q2oTZvw.png" /></figure><p>Step 3: Choose the<em> org.wso2.msf4j archetype</em>. If it is not listed, click on <em>Add Archetype</em> and fill out the fields, see<em> Figure: Adding MS4FJ Archetype</em>. Click on <em>Next</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/535/1*PoOw4blat6ftSl33YXe0XA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*gKoV5_b0xd2eDWYoigP6rw.png" /><figcaption>Adding MSF4J Archetype</figcaption></figure><p>Step 4: Provide the following inputs. At this part, <em>Order service</em> will be created (will later on work on the Recipe service). Click <em>Finish</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/534/1*Urz5AS9qbtUm3j6W_RUU1A.png" /></figure><p>Step 5: Click on the <em>Order </em>project’s <em>Application </em>class and click the <em>play </em>button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nw5wVrFoXGe8fosdMuHRyA.png" /><figcaption>Order Microservice is running on port 8080</figcaption></figure><h3>Hooray! We have created our first MicroService!</h3><p>With just 5 steps, we have created our first microservice called Order. Let us dive into the code and analyze the components.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JAZquskj8V0w-JY_c1L0Sg.png" /></figure><p>This microservice has <em>Application </em>and <em>OrderResource </em>classes. The <em>Application </em>class takes care of deploying the Order microservice — It creates a new <em>OrderResource </em>object, starts it, and deploys it at the default port 8080.</p><p>After all of those, our first microservice is up and running. OrderResource microservice is available at the path <strong><em>/service</em></strong><em>.</em> Once we opened our favorite browser and typed in <strong><em>http://localhost:8080/service</em></strong>, it goes to the port 8080 and finds the service path. Since this is a get method, within the service path, it goes to the get method with the GET annotation and path “/” and performs whatever is inside the method. In this case, it will print out <strong>Hello from WSO2 MSF4J</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*7R-Wvt7vcsAU4qpLOsh2LA.png" /></figure><h3>Demo 2: Order Service</h3><p>In this part of the demo, we will slowly build our Order Service with all the functionalities listed in our Business Rules in NetBeans.</p><p>Step 1: Open the Order Microservice that was created using Eclipse before by clicking on the <em>Open Project</em> icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/329/1*bu2X2g800Fv_vmOm2sVRZA.png" /></figure><p>Step 2: Go to the directory where you saved the project, select it, and click on <em>Open Project</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*LvsZmulea7ncaGisA2H6Og.png" /></figure><p>For this part of the demo, we will build our Order Microservice using a 4-tier architecture — remember that each Microservice can have its own architecture, but has to be careful. This means that we will be having 4 packages: application, database, models, service.</p><p>Step 3: Create new packages. Right-click on <em>Source Packages</em> &gt; <em>New </em>&gt; <em>Java Package</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/330/1*jQnXfXVw05mqFU521iFKXg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*3So_q4mVYMa49FxqSAbrNw.png" /></figure><p>We should end up with the following package structure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/395/1*BJbOj5yFkfs-xpjyG_pA5g.png" /></figure><p>The application package will contain the microservice classes, which are the Application class and OrderResource class. The database package will contain all the files that relates to accessing our database (which includes the script, utilities, and brokers). The models package will contain the entity classes from the database, and the service package will contain the classes used to access the brokers in the database package.</p><p>Step 4: Copy the following SQL script, DBUtil code, and OrderBroker code under the database package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ddf3e54848cf67f124b1a4161d816902/href">https://medium.com/media/ddf3e54848cf67f124b1a4161d816902/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/066a1a848703965aaf7f7c62d191f223/href">https://medium.com/media/066a1a848703965aaf7f7c62d191f223/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4565e5a6ff057783e3699eb8d86181c1/href">https://medium.com/media/4565e5a6ff057783e3699eb8d86181c1/href</a></iframe><p>Step 5: Generate new entity models from database. <strong>Make sure you ran the orderDB.sql script first</strong>. Right click on the <em>models package</em> &gt; <em>New </em>&gt; <em>Entity Classes from Database…</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/364/1*H9kR29tBx2VAOeJAtqr42w.png" /><figcaption>Select Entity Classes from Database…</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/442/1*P69_bK0d1MfHIczonIwOcA.png" /><figcaption>Select order &gt; Add &gt; Next</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*SzSQU05oUW5QXHE47vY9Ow.png" /><figcaption>Rename to Order_ &gt; Next</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*GmTp8TK9RbeWZoJv1uyVrA.png" /><figcaption>Set Association Fetch to eager &gt; Set Collection Type to List &gt; Finish</figcaption></figure><p>Step 6: Copy the OrderService code under the services package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3079c8c332ebd7d64d8b0290c4f7c26c/href">https://medium.com/media/3079c8c332ebd7d64d8b0290c4f7c26c/href</a></iframe><p>After all of those, our project structure should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*7mM1KQGTkD7EP0AFbkAhQQ.png" /></figure><p>Now all we have left is the functionalities of our Order. Based on the business rules, Order should have the following methods:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/244/1*ea8bNZkMjX00DUJtO1OPHQ.png" /></figure><p>From the model above, Order Service has two functionalities to perform: viewOrders. and createOrders(). The viewOrders() method is used to view all of the orders in the database — This means that we are getting from the database, and so this method will use the GET annotation. The createOrders() method is used to create an order and eventually add it into the database — This means that we are adding or putting an object into the database, and so this method will use the PUT annotation.</p><p>When we are creating methods for our Microservice, we have to make sure to use the appropriate REST annotations. The annotations are as follows:</p><ul><li><em>GET (used to tell that this method does the get/retrieve functionality)</em></li><li><em>PUT (used to tell that this method does the add functionality)</em></li><li><em>DELETE (used to tell that this method does the delete functionality)</em></li><li><em>POST (used to tell that this method does the edit functionality)</em></li><li><em>PATH (identifies the path to the method to run)</em></li><li><em>PATHPARAM (used to map the PATH parameters to method parameters)</em></li><li><em>PRODUCES (used to indicate that this method returns an object)</em></li><li><em>CONSUMES (used to indicate that this method takes an object)</em></li></ul><p>Step 7: <strong>viewOrders()</strong></p><p>a.) First, create a regular java method that returns a list of Order_ objects from the database.</p><pre>public List&lt;Order_&gt; viewOrders() {<br>        // create new OrderService<br>        OrderService os = new OrderService();</pre><pre>        // call the method to get all the orders and return it<br>        return os.getAllOrders();<br>}</pre><p>b.) Add the annotations at the top of the method.</p><ul><li>Identify that <em>this </em>method is GET</li><li>Identify the PATH to <em>this </em>method</li><li>Identify that <em>this </em>method returns an object</li></ul><pre>@GET<br>@PATH(&quot;/vieworders&quot;)<br>@PRODUCES(MediaType.APPLICATION_JSON)<br>public List&lt;Order_&gt; viewOrders() {<br>        OrderService os = new OrderService();<br>        return os.getAllOrders();<br>}</pre><p>This states that the viewOrders method is available at /service/vieworders and returns a JSON object back to the browser.</p><p>We can test this out using Postman. Postman is a software used to create requests and build responses without using an actual browser. To test our viewOrders method, we have to run our Microservice first. Click on the project and hit the run button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*yjlBZcNXcfv-o1MuzMhADw.png" /></figure><p>Launch Postman. Choose GET from the dropdown and type in the <em>path </em>to the method. Click <em>Send</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/933/1*J3CHRJVEKcEibpFm2hrxBQ.png" /></figure><p>Step 8: <strong>addOrder()</strong></p><p>a.) First, create a regular java method that takes in parameters to create an Order object that eventually will get added into the database.</p><pre>public Order_ addOrder(String tableNumber, String orderName) {<br>     // create new OrderService<br>     OrderService os = new OrderService();</pre><pre>     // create an Order object from the parameters<br>     Order_ order = new Order_<br>     (0, Integer.parseInt(tableNumber), orderName);</pre><pre>     // add the Order object into the database<br>     os.addOrder(order);</pre><pre>     //return the Order object<br>     return order;<br>}</pre><p>b.) Add annotations at the top of the method.</p><ul><li>Identify that <em>this </em>method is POST</li><li>Identify that PATH to <em>this </em>method.</li><li>Identify the parameters needed for the PATH.</li><li>Identify that this method PRODUCES an object</li><li>Identify that this method CONSUMES an object</li><li>Map the PATH parameters to method parameters</li></ul><pre>@POST<br>@PATH(&quot;/addorder/{tableNumber}/{orderName}<br>@PRODUCES(MediaType.APPLICATION_JSON)<br>@CONSUMES(MediaType.APPLICATION_JSON)<br>public Order_ addOrder<br>     (@PathParam(&quot;tableNumber&quot;) String tableNumber,<br>      @PathParam(&quot;orderName&quot;) String orderName) {</pre><pre>     OrderService os = new OrderService();<br>     Order_ order = new Order_<br>     (0, Integer.parseInt(tableNumber), orderName);<br>     os.addOrder(order);<br>     return order;<br>}</pre><p>This states that addOrder method is available at /service/addOrder and it takes in parameters <em>tableNumber </em>and <em>orderName. </em>This method consumes and produces a JSON object. The PATHPARAM annotation tells that the <em>“tableNumber”</em> in the PATH parameter will be identified as the <em>“tableNumber”</em> parameter in the method (same thing will follow to orderName).</p><p>Again, we can test this using Postman. Re-run the project. Launch Postman. Choose POST from the dropdown and type in the path and required parameter in the text field. Click <em>Submit</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*poa4iaI0a1JAwrWCr5hk_A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/924/1*GzRa-yr9pEXaONqDC0BCIA.png" /></figure><p>Below is the entirety of the Order Service code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b0e7b4a75b688ca9c871ddc917f5cdd8/href">https://medium.com/media/b0e7b4a75b688ca9c871ddc917f5cdd8/href</a></iframe><p>Now we are done with the Order Service! All we have left to do is the Recipe Service and I will leave that as an exercise :) If you ever feel stuck at any point of this demonstration, feel free to check out my Github repositories for this demo: <a href="https://github.com/zoebrianlavena/Microservice-MSF4J-OrderService">Order Service</a> and <a href="https://github.com/zoebrianlavena/Microservice-MSF4J-RecipeService">Recipe Service.</a></p><h3>Conclusion</h3><p>When building Microservice using the MSF4J Framework, we have to make sure we have an understanding of the business rules to better design and build a service. When building a service, we have to take note of the port and path that this services will be available — As well as the path for its method/functionalities.</p><p>Microservice-based projects are easy to maintain as you can build services and define it at different ports. It provides flexibility on the choice of the languages and tools used to build each services.</p><h3>References</h3><p>[1] C. Richardson, <em>Microservices Patterns with Examples in Java</em>. New York: Manning Publications Co., 2019, pp. 44.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=60c5414064d4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sw-d/microservices-60c5414064d4">Microservices</a> was originally published in <a href="https://medium.com/sw-d">SW|D</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservice:]]></title>
            <link>https://medium.com/sw-d/microservice-4609d656ccf8?source=rss-88e53ea71bc5------2</link>
            <guid isPermaLink="false">https://medium.com/p/4609d656ccf8</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Zoe Lavena]]></dc:creator>
            <pubDate>Sat, 09 Feb 2019 23:36:25 GMT</pubDate>
            <atom:updated>2020-03-15T06:27:53.220Z</atom:updated>
            <content:encoded><![CDATA[<h3>Understanding the Background of Microservice Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*DIPSefpcw2L1ZuH1T-XHPw.jpeg" /></figure><h3>Software Architecture</h3><p>There are numerous definitions of software architecture, take a look at these definitions found at this <a href="https://en.wikiquote.org/wiki/Software_architecture">link</a> [1] for example. My favourite one comes from Dewayne Perry and Alexander Wolf because of how it describes software architecture in a visual manner, which states [2]:</p><blockquote>By analogy to building architecture, we propose the following model of software architecture:</blockquote><blockquote>Software Architecture = { Elements, Form, Rationale }</blockquote><blockquote>That is, a software architecture is a set of architectural (or, if you will, design) elements that have a particular form.</blockquote><blockquote>— Foundations for the Study of Software Architecture by D. Perry and A. Wolf</blockquote><p>The analogy of <em>house and software architecture</em> is one way to have a concrete and visual understanding of what software architecture really means.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*Tf_Ns6iGEyO1FMRN90-hNg.jpeg" /><figcaption>House : Software Architecture</figcaption></figure><p>When building a house, we decide on how we wanted to lay it out, and eventually build it with pillars and walls. All houses have windows and doors, which are used to communicate (or to socialize) with the outside world. We need protection from the weather (heavy rain, snow storm, or extreme heat) and that is why houses have roofs. Of course, every houses have to be resilient and need a firm foundation.</p><p>In comparison to software architecture, we are going to start with the basics of building an application. All applications have an algorithm which are laid out using a programming language or two. An application communicates with other applications or services using an API — In a client-server perspective, we get requests and responses. The data, which are the foundation of an application, should be protected and secure by using security mechanisms.</p><p>There are numbers of ways on how we can compare houses to software architecture, these are just the basics. Another example can be the interior of a house, where as in software architecture we have the User Interface and User Experience (the look and feel, and how we interact with the entity).</p><p>We have to understand that all forms of architecture are important, for these are the basis of everything — From houses to buildings, from software entities to machines. <em>Software Architecture is important because of the two requirements of a system: Functional requirements and Non-Functional requirements [1]</em>. The whats and hows of a system are the reasons why we build applications. Without the users (the providers of requirements), software applications are just nothing.</p><p>Now that we have an idea of what software architecture is, we are going to run through the evolution of it. This will help us understand the different software architectures, and different ways of building and constructing an application. This will also eventually help us understand as to why Microservice Architecture is created.</p><h3>Evolution of Software Architecture</h3><p>It all started with a mainframe, where the client does the processing and the server acts as a centralized data repository.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*vJ54WwrfCLNJUxXilnU6hg.jpeg" /><figcaption>Mainframe architecture [3]</figcaption></figure><p>This later introduced us to the UI Browser Client Architecture, where a server receives requests from and sends responses back to the client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*eoiJEPwXb9HE4nPi_STulQ.jpeg" /><figcaption>UI Browser Client Architecture [3]</figcaption></figure><p>Everything is going happy and well when the server has started to have multiple responsibilities, thus slowing down the application. Software architects solved this issue by creating the N-Tier architecture, where an application is divided into layers and structured in a way that each layers has its own responsibility [3].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KoHM7aPeGE3cIRatctHvXg.jpeg" /><figcaption>N-Tier (Layered) Architecture [3]</figcaption></figure><p>This architecture, as far as I know and based on experience, is the most popular way of structuring a simple architecture. Some problems with this are the ideal dependencies of each layer and the ways of managing changes better. If you are not a fan of this architecture and you wanted to reduce the dependencies of layers to <em>manage changes better [3]</em>, you may want to structure your application using the Onion Architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*rN7WCmFwn1yOPwi1sscZIA.jpeg" /><figcaption>Onion Architecture [3]</figcaption></figure><p>The main difference between an N-Tier architecture and Onion architecture are the directions of the arrows (arrows represents the dependencies). The N-Tier architecture has two arrows — one that goes down and one that goes up, which means each layers has a two-way dependency. Where as the Onion architecture has only one arrow — an arrow that goes down, which means that only the outer layers depend on the inner layers and not the other way around.</p><p>The Hexagonal architecture is one variation of resolving the dependency problem. This <a href="https://blog.ndepend.com/hexagonal-architecture/">link</a> briefly describes the hexagonal architecture in a straightforward manner.</p><p>At this point, problems relating to data management has escalated. The first problem are due to when <em>technology become a way of life [3]</em>, meaning that we have more users which means more data to handle. This raises issues in scalability and response time. One way to deal with this is by applying the CAP Theorem — Consistency, Availability, Partition Tolerance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xehg6fTadI9wD9BzG5YN8Q.jpeg" /><figcaption>CAP Theorem [3]</figcaption></figure><p>In a brief explanation, you can choose only two out of the three elements to manage your data. I will not go over this in much detail, but you can read more on this <a href="https://towardsdatascience.com/cap-theorem-and-distributed-database-management-systems-5c2be977950e">link</a>.</p><p>The second problem with data management is <em>when multiple users try to access the same piece of data [3]</em>, which raises issues in contention. One way to deal with this issue is by applying the idea of CQRS — Command Query Responsibility Segregation. In simple words, we separate the reads and writes of data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*5c7h66fJVPh3-MylmIRqJA.jpeg" /><figcaption>Command Query Responsibility Segregation [3]</figcaption></figure><p>Now that we are familiar with how architecture evolved, we can now move on to the next section of my blog. All of the architecture mentioned above, from Mainframe architecture to CQRS data management, are all forms of monolithic architecture.</p><h3>Monolithic Architecture…</h3><p>structures an application as a single executable and deployable component. Monolithic architecture is actually a good choice in building simple applications, but there is an architecture that is better for large and complex systems which will be covered in a moment. Some of the benefits of building a monolithic-based application are as follows [1]:</p><ul><li><em>Simple to develop</em></li><li><em>Easy to make radical changes</em></li><li><em>Easy to scale</em></li><li><em>Straightforward to test and deploy</em></li></ul><p>Since a monolithic-based application is a single component, we deliver, deploy, and test it easily in a straightforward manner. Once an application gets larger and even more complex, we face the following challenges [1]:</p><ul><li><em>Complexity</em></li><li><em>Slow development</em></li><li><em>Commit to deployment</em></li><li><em>Difficulty in scaling</em></li><li><em>Reliability</em></li><li><em>Obsolete</em></li></ul><p>A <em>large and complex monolithic-based application slows down the IDE of the developer which leads to development and deployment issues [1]</em>. This type of application may experience difficulty in adopting new features and new technology. To address these challenges, Microservice Architecture is developed and introduced to the industry.</p><h3>Microservice Architecture…</h3><p><em>structures the implementation view as a set of multiple components [1]</em>. The “<em>implementation view”</em> are the things produced by the build system (JAR, WAR), while the “<em>components” </em>means the services, and these services are connected by communication protocols.</p><p>Let’s visually describe the main difference of a monolithic-based architecture and a microservice-based architecture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/824/1*v-WppnwASefif28aS5KQ8A.jpeg" /><figcaption>Differences in structures between Monolithic and Microservice [3]</figcaption></figure><p>As you can see in the diagram above, the services in a monolithic-based application are all in one layer, hence the word <em>monolithic</em>. Where as in a microservice-based application, each service is a single and independent entity. Let’s take a look on the microservice’s most important element: <em>the service</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*Z6bBXLvUJqf4124L_9Tpkg.jpeg" /><figcaption>Service [1]</figcaption></figure><p>Illustrated above is a visual representation of <em>Accounting Service</em>. <em>A service is a standalone and independently deployed software component [1]</em>. It has its own language, architecture, and database structure.</p><p>A <em>service has an API which provides access to its functionalities to its clients [1]</em>(another service or an actual human). An API is divided into commands/queries and account event publisher to handle the inputs and outputs of the service. An API <em>encapsulates its internal implementation [1]</em>(modularity), and <em>enables the implementation of a service to change without impacting its clients [1] </em>(loose coupling). Those are the two essential components of a microservice-based application — Modularity and loose coupling.</p><p>Listed below are the benefits of implementing Microservice architecture [1]:</p><ul><li><em>Continuous delivery and deployment</em></li><li><em>Small and easily maintained</em></li><li><em>Independently deployable and scalable</em></li><li><em>Better fault isolation</em></li><li><em>Easy experimenting and adoption</em></li><li><em>Autonomous teams</em></li></ul><p>You can tell that the benefits of Microservice cancel out most of the challenges faced in a monolithic-based application, more specifically the ability to adopt new features and technology. Of course, no architecture is a silver bullet, listed below are the challenges faced of a microservice-based application [1]:</p><ul><li><em>Difficulty in finding the right set</em></li><li><em>Distributed systems are complex</em></li><li><em>Careful coordination</em></li><li><em>Transitioning</em></li></ul><p>There is a challenge in finding the right set because there is <em>no concrete and well-defined algorithm in building a microservice-based application [1]</em>.</p><h3>Beyond Microservices</h3><p>Building a microservice-based application is more than just the technical aspects of it, we also have to <em>consider the human side of deploying and delivering this type of application [1]</em>.</p><p>Having said that Microservice is a set of independently delivered and deployed services, each services has its own team. <em>Typically, a team consists of 8 to 12 members, and can deliver and deploy their own service without contacting the other teams [1]</em>. This allows the team to be autonomous, as listed in one of its benefits.</p><p>A team is proportional to its service. Once the service becomes larger, the team building it becomes bigger. To conform to the standards of Microservice, <em>the team has to be broken down into smaller groups and split the associated service or services [1]</em>.</p><p>When implementing a microservice-based application, you have <em>to practice continuous delivery (such as Agile development) and deployment (such as Scrum deployment practices) [1]</em>.</p><h3>References</h3><p>[1] C. Richardson, <em>Microservices Patterns with Examples in Java</em>. New York: Manning Publications Co., 2019, pp. 1–64.</p><p>[2] “Software architecture,” <em>Wikiquote</em>, 2014. [Online]. Available: <a href="https://en.wikiquote.org/wiki/Software_architecture">https://en.wikiquote.org/wiki/Software_architecture</a>. [Accessed: January 22, 2019].</p><p>[3] N. Bhatt, “Evolution of software architecture, “ <em>WordPress</em>, 2016. [Online] Available: <a href="https://nirajrules.wordpress.com/2015/12/09/evolution-of-software-architecture/amp/?fbclid=IwAR2jDDgJzRIWQtOTd8iMfrg5_RsF--KvOECMidbrcKuzl6kBPVoUfS-XmE8">https://nirajrules.wordpress.com/2015/12/09/evolution-of-software-architecture/amp/?fbclid=IwAR2jDDgJzRIWQtOTd8iMfrg5_RsF--KvOECMidbrcKuzl6kBPVoUfS-XmE8</a>. [Accessed: January 19, 2019].</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4609d656ccf8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/sw-d/microservice-4609d656ccf8">Microservice:</a> was originally published in <a href="https://medium.com/sw-d">SW|D</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>