<?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 Piyush Shrivastava on Medium]]></title>
        <description><![CDATA[Stories by Piyush Shrivastava on Medium]]></description>
        <link>https://medium.com/@piyushshri?source=rss-593567854dad------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k_Ou-9963BC_jjiZOcEF2w.jpeg</url>
            <title>Stories by Piyush Shrivastava on Medium</title>
            <link>https://medium.com/@piyushshri?source=rss-593567854dad------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 10:51:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@piyushshri/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[Designing Microservices Using Database Per Service and Saga Patterns]]></title>
            <link>https://medium.com/walmartglobaltech/designing-microservices-using-database-per-service-and-saga-patterns-98c0a547212f?source=rss-593567854dad------2</link>
            <guid isPermaLink="false">https://medium.com/p/98c0a547212f</guid>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[system-architecture]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Piyush Shrivastava]]></dc:creator>
            <pubDate>Fri, 01 Mar 2024 09:28:56 GMT</pubDate>
            <atom:updated>2024-03-01T09:28:56.296Z</atom:updated>
            <content:encoded><![CDATA[<p>The Microservices pattern has been the hype among developers for quite some time now, all because of its robustness and simplicity. It has enabled developers to write applications quickly and in a more integrated way. While a lot of developers are creating state-of-the-art architectures using microservices, it also has antipatterns that cause more harm than good. Understanding various microservice patterns is very important to avoid basic design mistakes that developers make. In this post, let’s discuss database patterns in the context of microservices paradigm and how they can be implemented. We will look at what these patterns are and how they have been used in the e-commerce space.</p><h3><strong>Database per Service Pattern</strong></h3><p>Usually, a monolith application has a single big data store that stores the data for all the needs of the application. In microservices, we divide the application into independent services. The database per service pattern suggests having independent, scalable and isolated databases for each microservice instead of having a common datastore. Each service should independently access its own DB, services cannot access each other’s DBs directly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XK7hJD5gpkD1D9knUdo9zw.png" /><figcaption>Database per service pattern</figcaption></figure><p>This pattern ensures loose coupling between services, any issues, or changes in one service would not affect any other service or its database. Also, it is not necessary to use a single type of DB for all services. Each service can choose its database according to its requirements.</p><h4><strong><em>Example Scenario</em></strong></h4><p>Let us take examples of some of the most common services that any e-commerce platform requires. The typical Orders flow is handled by multiple services. Two services that the order management system interacts with are item service and inventory service. Item service needs data related to items, their cost, sellers selling it, and inventory service needs data related to how much inventory is left for the items. Both data storage requirements are related, but if we store them in a single database, it will become huge, complex, difficult to manage and the queries (especially joins) will take a lot of time to execute.</p><p>To solve this problem, we can use the database per service pattern. An items database will store items data and another inventory database will store inventory data. Items service will connect to items db and inventory service will connect to inventory db. This way, if there is any issue in items service, inventory service will still keep running.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/930/1*Veo5rJfsWQVQ4x2KXk0j-w.png" /><figcaption>In database per service pattern, each service has its own database</figcaption></figure><h4><strong><em>How to run queries that require data from more than one service?</em></strong></h4><p>One fundamental problem to solve here is what happens if reading data from both items and inventory databases is required. For example, if I need the item name along with inventory numbers for all sellers selling that item? In this case, usually we would perform a join if there was a single database and two tables in it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d_EI_68wnNa9A5OodgVPCg.png" /><figcaption>Services don’t access each other’s database directly (Data access using API composition)</figcaption></figure><p>The applications can perform the join instead of the database performing the join. If the items service requires data from inventory service, it can request. The inventory service will have APIs to provide this data. For example, for inventory for a specific item, the item name can be retrieved from the items db, and then using the item id, an API request can be sent to inventory service to get the inventory for that item id. This is known as API composition. One of the ways of achieving this is by using the Saga pattern, as explained further below.</p><h4><strong><em>Advantages Over Single Shared Database</em></strong></h4><p>You get the following benefits by using the database per service pattern for designing your microservices.</p><ul><li>Faster development — There is no development time coupling between services; each service can be developed independently. For example, if a developer working on items service wants to update the schema of its db, they can do so. The schema of inventory service would not be affected, thus development on inventory service can continue without interference.</li><li>No runtime interference — Any queries on one database will not affect other services. If a query on orders service is taking time to run, queries on inventory service can still execute. Or if inventory service puts a lock on any data item in its database, data in the other databases is not locked.</li><li>Freedom to choose different databases — A single database may not be suited for all microservices. If one service requires a relational database and another service requires a NoSQL database, they are free to choose. In the case of shared database, a single type of db has to be used by all the services, but database per service pattern gives the independence for services to use the database type they require for their use case.</li><li>Fault Tolerance — If orders service database fails, inventory service will still be operational. Database per service pattern gives more fault tolerance than shared database pattern.</li><li>Loose coupling — Changes in one database will not affect the other databases. In case of a shared database, suppose if the orders data has to be moved from one type of db to another type, the whole database needs to be moved. In the case of database per service, only the orders data can be moved independently.</li></ul><h4><strong><em>When not to use Database per Service</em></strong></h4><p>While it is immensely helpful to use this pattern in large sets of microservices, it is not advisable in the following scenarios:</p><ul><li>In a transaction-heavy system, it might become difficult to use multiple databases. A single RDBMS system is best suited for such use cases. For example, implementation of a banking application where multiple services can do transactions, such as customer service and account manager service should be done using a shared database design to maintain reliability of the transactions.</li><li>Queries that require complex joining of multiple tables might be difficult to implement in this pattern. For example, services that require complex searching use cases where data needs to be derived using joins.</li></ul><h3><strong>The Saga Pattern</strong></h3><p>The word “saga” means a long story with many events. That is what we are also trying to achieve. We are trying to read data that is residing in a database that is not directly readable from the service we want to read it in. If our service is the start of the story and the database is the end, we will be performing a series of local transactions in the intermediate services that will act as the various events of our story.</p><p>When a request is received at our receiving service, it will perform operation at its local database and send an event to the next service. This will go on until the whole saga is executed. To attain atomicity, each local transaction has a rollback transaction that will revert the database in case its local transaction fails.</p><p>So, if we take our ecommerce example, if a user requests to purchase an item, the item service will read the item details from its local database and send these details via an event to the inventory service. The inventory service will then check the inventory details for the given items in its local database and update the inventory if available. It then sends a response back to the items service and the item service completes the transaction.</p><p>In case the transaction at inventory service fails, it will send a compensatory response to items service indicating a failed status for the transaction. If the inventory database is already updated, it is the responsibility of this compensatory transaction to revert it to its original state.</p><h4><strong><em>Implementation</em></strong></h4><p>There are two ways of implementing the saga pattern in a microservices based system, <em>choreography,</em> and <em>orchestration</em>.</p><p><strong>Choreography</strong> is simply implementing sagas using events. Each service sends an event directly to the next service it wants to trigger and receives a response in return. Here, there is no central service dedicated to managing the transactions. Therefore, choreography is the decentralized way of implementing sagas. The main advantage it provides is that there is less coupling between the services. Scalability is easier and there is no single point of failure. The drawback is that it is harder to monitor, maintain and test as there is no central system.</p><figure><img alt="Choreography based saga" src="https://cdn-images-1.medium.com/max/1024/1*sVLLN3H5lQgjC-p1-pgjig.png" /><figcaption>Choreography based saga</figcaption></figure><p>Using choreography, our item service will invoke an event for the inventory service to get the data it needs, the inventory service will receive the event, perform its local transaction, and send the response back to the items service. In case any local transaction fails, a compensating transaction will be invoked. For example, if inventory service updates the inventory and sends the response back to the item service, but the item service fails to send data to the user, it will send a compensating transaction to inventory service for reverting its database to its original state.</p><p><strong>Orchestration</strong> involves a centralised service called the <em>orchestrator</em> that receives each request and contains the business logic to decide which service to call next based on the request. The advantages this brings is that it is easier to monitor the transaction through the orchestrator, it is easier to maintain and test the orchestrator as responsibilities are more segregated between the services. The drawbacks are that the orchestrator can become a single failure point for the transactions and must be individually scaled and replicated, increasing coupling between the services.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ab7aiQTq-yCbtgOkr_KyPw.png" /><figcaption>Orchestration based saga</figcaption></figure><h3><strong><em>Summary</em></strong></h3><p>The database per service pattern allows services to have their own databases instead of a single shared database. This makes the services loosely coupled, and they can be individually developed, deployed, tested and scaled. Transactions that require data from more than one service are implemented using API composition. One pattern that can be used to implement this is the Saga pattern. It defines concepts like choreography and orchestration which are different ways to implement transactions that span services.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98c0a547212f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/walmartglobaltech/designing-microservices-using-database-per-service-and-saga-patterns-98c0a547212f">Designing Microservices Using Database Per Service and Saga Patterns</a> was originally published in <a href="https://medium.com/walmartglobaltech">Walmart Global Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streamlining Software Engineering With The Scientific Method]]></title>
            <link>https://medium.com/walmartglobaltech/streamlining-software-engineering-with-the-scientific-method-15015a43c6ed?source=rss-593567854dad------2</link>
            <guid isPermaLink="false">https://medium.com/p/15015a43c6ed</guid>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Piyush Shrivastava]]></dc:creator>
            <pubDate>Wed, 13 Jul 2022 06:13:54 GMT</pubDate>
            <atom:updated>2022-07-13T06:13:54.582Z</atom:updated>
            <content:encoded><![CDATA[<p>The scientific method is one of the oldest well-defined processes to observe, record and share knowledge with its practice dated as early as the 17th century. It is widely used by scientists, researchers and scholars to conduct and document experiments and writing research. I have found this process very interesting and I feel that it can be used to streamline any job, especially in Software Engineering. This article, let’s discuss how.</p><h3>What is the Scientific Method?</h3><p>In simple words, the scientific method is a method or a process for validating and documenting an experiment by means of making observations and testing them against measurable data. This method is widely used by scientists in the process of experimentation, to validate that their observations hold correct. The typical steps involved in this method are:</p><ol><li>Formulation of a problem statement/question</li><li>Making a hypothesis</li><li>Testing the hypothesis with experimentation</li><li>Analysis of the outcome</li><li>Communicating results</li></ol><p>There are many articles and scientific journals available about the details of this process, so I will not go deep into what these steps are. Let’s see how software engineers can apply these steps in their work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qbpQXCjN4NHQ5BNCykX13g.png" /><figcaption>Steps of the Scientific Method (Image Source: <a href="https://en.wikipedia.org/wiki/Scientific_method#/media/File:The_Scientific_Method.svg">Wikipedia</a> Licensed under <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>)</figcaption></figure><h3>Thinking of Tasks as Experiments</h3><p>Any task that an engineer has to do in a typical work day can be seen as an experiment. Lets take an example of coding some functionality in a software. Normally, an engineer would design the structure of the code in their mind, think of how to store and handle data, how to implement the business logic and then maybe how to integrate it with the existing system. Thinking of this task as an experiment will include defining it properly, like a problem statement or a question, documenting the progress, thinking of multiple ways to solve/answer it, taking all the outcomes into consideration, validating it against a source of truth and finally communicating the results in documentation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7C5krdAXTCY4fKMBstCDdQ.png" /><figcaption>Task vs. Experiment</figcaption></figure><p>This way, the task can be recorded like how we used to record experiments in a lab file in our science labs in school. An engineer can showcase their discovery about the tasks, what assumptions they made, how many methods of completing the task they considered and how they came up with the best method, what failed and what succeeded and the plan for integration or deployment.</p><p>This will encourage a much better way of defining the tasks and their scope correctly. A well defined problem is much more likely to be solved than a loosely defined one.</p><h3>Hypothesis Testing For Assumptions and Observations</h3><p>Creating hypotheses and testing them is a great tool for doing almost anything. In software design, we make many decisions where we have to consider between multiple options and select what is the best for the product. While conducting discovery about such decisions, hypothesis testing can be of good benefit. For an example, an engineer wants to choose the best database for their product. They will have to go through the pros and cons of all the available options and select what is the best for them. They can create a hypothesis, say, “SQL should be used for transactional systems”. Testing this hypothesis, by design will force them to consider and document all the data available to support this assumption. They will have to observe and record measurable benchmarks. This way, by the end of the experiment, they will have the definitive solution for their problem, supported by data that they can pitch to their leads, management or any other stakeholder with confidence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XkSBMcVlIkqXPI3WYrEL6Q.jpeg" /><figcaption>Hypothesis Testing (Attribution: <a href="https://commons.wikimedia.org/wiki/File:4_stage_Scientific_Method.jpg">Brightyellowjeans</a>,<a href="https://creativecommons.org/licenses/by-sa/4.0"> CC BY-SA 4.0</a>, via Wikimedia Commons)</figcaption></figure><h3>Paper Worthy Outcomes</h3><p>Communicating is one of the most important and also one of the most ignored aspect of engineering. Anything that an engineer can work on should be communicated clearly, whether over emails, JIRA stories, or wiki pages. The last step of the scientific method is to communicate the outcomes. Scientists usually communicate outcomes via research journals where they publish their papers. Research papers is the best form of documentation that there can be. That is how even engineering documents should be created. A good document should start with defining the problem that was being solved, what experiments were conducted to solve it and what are the outcomes of those experiments. If we take the same example of writing code for a functionality in a software, the engineer should create a document describing the following:</p><ol><li><strong>The problem statement:</strong> What was the requirement, who defined it</li><li><strong>Discovery/research:</strong> What tools are being used, which systems are getting integrated, what assumptions are made</li><li><strong>Hypotheses and tests:</strong> The design decisions considered, data structures used, why they were chosen backed with measurable data</li><li><strong>Outcomes:</strong> Software testing results, performance insights</li><li><strong>Result:</strong> Final deliverable</li></ol><h3>Conclusion</h3><p>The scientific method, although designed for scientists, inspires many good practices that can be applied in day to day software engineering. There are many more such practices that can be interoperable with engineering. If you are aware of any other methodology or process that has helped or inspired you in how you perform your day to day tasks, do let me know in the comments section. Thank you for reading.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15015a43c6ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/walmartglobaltech/streamlining-software-engineering-with-the-scientific-method-15015a43c6ed">Streamlining Software Engineering With The Scientific Method</a> was originally published in <a href="https://medium.com/walmartglobaltech">Walmart Global Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Blocks Of Scalable Enterprise Integration Engines]]></title>
            <link>https://medium.com/walmartglobaltech/building-blocks-of-scalable-enterprise-integration-engines-66cb5046626f?source=rss-593567854dad------2</link>
            <guid isPermaLink="false">https://medium.com/p/66cb5046626f</guid>
            <category><![CDATA[scalable-systems]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[system-integration]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Piyush Shrivastava]]></dc:creator>
            <pubDate>Wed, 03 Nov 2021 09:33:06 GMT</pubDate>
            <atom:updated>2021-11-03T09:33:06.046Z</atom:updated>
            <content:encoded><![CDATA[<p>Service to the Customer is one of the core values which drives global supply chains and we apply our heart and soul for it. Many people and systems located across the world come together every day in a man-machine harmony for providing the best services possible. We also communicate with many partners and service providers to procure and deliver products across the world.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*NRRjC1mWNo84qbeoVZDmvg.jpeg" /><figcaption><a href="https://www.flickr.com/photos/91261194@N06/49746754066">Image Source</a> Licensed Under <a href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a></figcaption></figure><p>Integration engines play a major role in organizations based in industries such as e-commerce where so many entities both on and off the company are working together. They range from very small, integrating just a couple of systems to very large, handling the load of almost all the major processes. In this article, let us discuss how an enterprise-level integration engine can be designed they manage and scale to serve important use cases.</p><h3>The Problem</h3><p>Any e-commerce service provider has to integrate multiple systems which handle specific parts of the e-commerce use cases. Let’s take order fulfillment as an example. From the outside, it might seem a simple process to select and place an order and wait for it to get delivered, but many systems and teams work together for it. The order is placed on a website which itself is one of the systems. The checkout system is responsible for verifying and generating the actual customer order which is propagated to other systems. There is a system that reserves the customer’s items and decides on a delivery date based on the nearest available shipping locations. Another system takes care of orders that are to be sent to the respective partners and a system that integrates all of these and talks to partners outside the intranet. There are many more systems that directly and indirectly contribute to fulfillment such as monitoring, compliance, rule processors, etc.</p><h3>What do we need?</h3><p>We base our integration engine on a message-based architecture. What we mean by this is that the smallest unit of work in our system is a message. Messages can be passed from one component to the other as well as can be monitored, tracked and reprocessed.</p><p>The recipe for the perfect integration engine would need the following categories of ingredients:</p><ol><li>Integration mediums</li><li>Processing Engine</li><li>Event processors</li><li>Communication mediums</li><li>Data storage mediums</li><li>Databases</li><li>Search Engine</li><li>Monitoring systems</li></ol><p>Since our integration engine has to work at scale, we need to account for the distribution of all these components. There are many tools available. Our state-of-the-art cloud management application, <a href="https://oneops.github.io/">Oneops</a> is perfect for this job. With its built-in support for load balancers, Oneops provides distribution of load, managing deployments, creating and managing virtual machines and much more. Let’s take a look at the tech stack requirements that we can consider,</p><ol><li>File-based integration, HTTP based integration, Messaging queue-based integration</li><li>A distributed application to process messages</li><li>High-velocity event processing engine</li><li>Distributed messaging queues as a communication medium for both inside the engine and outside integrations</li><li>An Object store for files and media storage</li><li>No-SQL DB to store historical data and configurations, relational DB to store transactional data</li><li>A search engine to index and search data for monitoring</li><li>Monitoring system with UI</li></ol><figure><img alt="Integration Engine Overview" src="https://cdn-images-1.medium.com/max/1024/1*xZp8aEQn-Xrd-ICy42YbhA.png" /><figcaption>Integration Engine Overview</figcaption></figure><p>There are several technologies available to fill in these requirements. Any of them can be fit in and our integration engine is ready to serve.</p><h3>Distributed Architecture</h3><p>Distribution can happen at multiple places. Firstly, we use distributed databases and messaging queues. What we need to solve is to distribute the computation. To do this, we have components deployed on various virtual machines across data centers. We can use any load balancing method to distribute the incoming load to our servers into these VMs. Once the message is received in one Virtual Machines on the server, the computation can be further divided and distributed inside the processing engine. The distributed messaging queue plays a major role here as each node can process a different message and send it to its nearest database node to be stored. This gives us fast and reliable scalability.</p><h3>High Availability</h3><p>Distribution in itself ensures high availability. Oneops enables us to monitor the health of the Virtual Machines so that we can repair or replace them in time. We also distribute our application across multiple data centers to account for disaster recoverability. Fault tolerance is further ensured by the monitoring system. All of these factors enable us to create an enterprise-level integration system that is ready to serve the huge amount of transactions a typical e-commerce service serves every day with minimal chances of failure.</p><h3>Primary Use Cases and How to Solve Them</h3><p>Below are some of the use cases that our Integration Engine can solve.</p><h4>Transformation</h4><p>We get data from various systems, merge it, convert it into a format supported by external partners and relay it to them. The major challenge here is that each partner may be expecting data in a different format. Our processing engine should support anything and everything. To implement this, we use a rule-based transformation framework. This makes it easy to plug in new rules for any new format which needs to be supported.</p><h4>Aggregation</h4><p>We aggregate data before sending it to partners depending on configurable batch size and duration. This is achieved by accumulating it into our transactional database until our event processor generates events for processing them. The events can be based on the amount of data or time.</p><h4>Unified Message Processing</h4><p>We receive messages from many systems. Instead of coding consumers for each of these systems, we use an integrated, configuration-based listener which supports many popular messaging queues. Details of the queue can be added in the configuration and the system should be ready to consume from it.</p><h4>Monitoring</h4><p>Monitoring is a crucial part of the system. The monitoring system is an application that displays data stored in our databases and object store through the search engine for various stakeholders to view the status of messages. It has options to help support teams troubleshoot problems and reprocess failed messages. It also has graphs for monitoring the health of all the components of the tech stack and an alerting system for letting the stakeholders know if anything is not working.</p><h4>Custom Use Cases</h4><p>Since this is a generic integration engine, we support plug-and-play use cases. Any functionality can be coded into it as required if it needs integration between systems. The integration engine provides the infrastructure and resources for any use case while the core logic can be coded and added into it.</p><h3>Integrate Away…</h3><p>With these components in place, we can start integrating systems. Our integration engine should be able to scale, take care of multiple formats, aggregate, process messages, be fault-tolerant and resilient to new requirements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=66cb5046626f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/walmartglobaltech/building-blocks-of-scalable-enterprise-integration-engines-66cb5046626f">Building Blocks Of Scalable Enterprise Integration Engines</a> was originally published in <a href="https://medium.com/walmartglobaltech">Walmart Global Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>