<?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 Aditya Rao on Medium]]></title>
        <description><![CDATA[Stories by Aditya Rao on Medium]]></description>
        <link>https://medium.com/@arao1729?source=rss-a861eab7a8e2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*C6Q6-lXwfuwa9Bnd</url>
            <title>Stories by Aditya Rao on Medium</title>
            <link>https://medium.com/@arao1729?source=rss-a861eab7a8e2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 20:12:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@arao1729/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[CQRS — A simple yet elegant architectural design pattern]]></title>
            <link>https://arao1729.medium.com/cqrs-a-simple-yet-elegant-architectural-design-pattern-3beae98c8bf0?source=rss-a861eab7a8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3beae98c8bf0</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[system-architecture]]></category>
            <dc:creator><![CDATA[Aditya Rao]]></dc:creator>
            <pubDate>Sat, 06 Mar 2021 12:57:38 GMT</pubDate>
            <atom:updated>2021-03-06T12:57:38.032Z</atom:updated>
            <content:encoded><![CDATA[<h3>CQRS — A simple yet elegant architectural design pattern</h3><p>CQRS (Command and Query Responsibility Segregation) — is a design pattern which separates your READ and WRITE/UPDATE/DELETE operations within your code.</p><p>In practice, CQRS is a very simple pattern that doesn’t require a lot of investment. It can be easily extended with more complex techniques like event-driven architecture, event-sourcing, or polyglot persistence. But they’re not always needed. Even without applying any extra patterns, CQRS can offer better decoupling, and code structure that is easier to understand.</p><p><strong>TLDR — You can get a high level understanding by just looking at this image</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*Bg2ua8uupay5RCBH5YlSeg.png" /></figure><h3>Use-Case</h3><p>Let is consider a basic CRUD Model for Orders in a restaurant and same business model — A Customer places order, rarely updates it or deletes it, but the same order is seen by the customer, the cashier, the cook\s and other people in between. This model is a READ Heavy model.</p><p>And this system is growing rapidly with new features, we would like to a menu, where each dish will have its ingredients, we also want to show the location where those ingredients are sourced from, we want to include the number of calories each dish has, so on and so forth.</p><p>This is a classic case of Data Driven system, where we have new entities nested inside each other, connected with one another, and lets add EVENTS to this mix — Such as OrderTaken, OrderCooked, OrderDeliverd, BillPaid and others.</p><p>On top of this we are expanding to new services, like customers can order online, they can ask for small changes in the ingredients — basically we are adding a ton of new business use case as we build the system</p><h3>What is CQRS</h3><p>The idea of CQRS is to divide the application into two different sections which work with different models:</p><ul><li>The Create-Update-Delete <strong>COMMAND </strong>which is responsible for creating or mutating the data, and the <strong>QUERY</strong> which fetches the data.</li><li>It also has an Internal model it writes with, and one or many models using which we can read(more on this later)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HTPOQG_2TXkcIIcOmm8D0g.png" /><figcaption>CQRS Command and Queries with their won model</figcaption></figure><h3>Commands</h3><p>Commands are the thing that writes with a model. It is used to create a new entity or change the state of the entity.</p><ul><li>A Command is an tasked based operation, rather than data centric.</li><li>A Command may be a Function call with an API.</li><li>A Command can be placed on a queue for async processing (Events, Tasks).</li></ul><p>In a way a Command can change the state, is an entity created, can cause change in the system directly or indirectly. In API terminology it is defined as Create/Update/Delete : Entity</p><p>A Command is <strong>behavior-centric</strong> and not <em>data-centric</em>. It is about the intent to change something, it does not map to the format of a resource (like DTOs in an API). It can contain data that will help to process the intent but that’s it.</p><p>We also talk about <strong>Task Based</strong> systems and not <em>Resource Based</em> systems. The Writes part doesn’t accept new resources or patch of existing resources: they accept tasks aka Commands.</p><h3>Query</h3><p>Queries are methods that are used to read data — <strong>These operations do not change the data </strong>with this you can imagine, wherein we have multiple data models which we might combine for a the response of an API — Such as UserModel and OrderModel to show all Orders made by said User.</p><p>The advantages of this system comes into play when we start adding other components to our architecture</p><ul><li>Adding cache</li><li>Faster queries ( We have can 3 DB’s to Read from and 1 DB to write)</li><li>Do a lot of precomputation on the backend — Helps keeping the client side lite.</li><li>High latency — there is a difference between Faster queries and this ;)</li></ul><h3>The Flow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z8GEGkLt2IkNRfa8rtpAPA.png" /></figure><p><strong>The Command Flow</strong>, here the API Model which is used by the client can do two things,</p><ol><li>It can create an entity using, mapping and validating with the internal model</li><li>It can trigger an Event, which is responsible to change the state of an entity.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TCXAjrdrAacq693E5Jr6bA.png" /></figure><p><strong>The Query Flow</strong>, is pretty straight forward, you have an client side need, that is either —</p><ol><li>Is part of a single internal model, where in it is fetched directly.</li><li>Or is a combination of the internal models, and there is some aggregation of models.</li></ol><h3>Advantages of CQRS</h3><ul><li><strong>Consistency </strong>— It is far easier to process transactions with consistent data than to handle all of the edge cases that eventual consistency can bring into play. Most systems can be eventually consistent on the Query side.</li><li><strong>Data Storage </strong>— The Command side being a transaction processor in a relational structure would want to store data in a normalized way, probably near 3rd Normal Form (3NF). The Query side would want data in a de-normalized way to minimize the number of joins needed to get a given set of data. In a relational structure likely in 1st Normal Form (1NF).</li><li><strong>Independent Scaling</strong> — CQRS allows the read and write workloads to scale independently, and may result in fewer lock contentions.</li><li><strong>Optimized data schemas</strong> — The read side can use a schema that is optimized for queries, while the write side uses a schema that is optimized for updates.</li><li><strong>Security</strong> — It’s easier to ensure that only the right domain entities are performing writes on the data.</li><li><strong>Separation of concerns </strong>— Segregating the read and write sides can result in models that are more maintainable and flexible. Most of the complex business logic goes into the write model. The read model can be relatively simple.</li><li><strong>Simpler queries</strong> — By storing a materialized view in the read database, the application can avoid complex joins when querying.</li></ul><h3>When to use CQRS</h3><p>Consider CQRS for the following scenarios:</p><ul><li>Collaborative domains where many users access the same data in parallel. CQRS allows you to define commands with enough granularity to minimize merge conflicts at the domain level, and conflicts that do arise can be merged by the command.</li><li>Task-based user interfaces where users are guided through a complex process as a series of steps or with complex domain models. The write model has a full command-processing stack with business logic, input validation, and business validation. The write model may treat a set of associated objects as a single unit for data changes (an aggregate, in DDD terminology) and ensure that these objects are always in a consistent state. The read model has no business logic or validation stack, and just returns a DTO for use in a view model. The read model is eventually consistent with the write model.</li><li>Scenarios where performance of data reads must be fine tuned separately from performance of data writes, especially when the number of reads is much greater than the number of writes. In this scenario, you can scale out the read model, but run the write model on just a few instances. A small number of write model instances also helps to minimize the occurrence of merge conflicts.</li><li>Scenarios where one team of developers can focus on the complex domain model that is part of the write model, and another team can focus on the read model and the user interfaces.</li><li>Scenarios where the system is expected to evolve over time and might contain multiple versions of the model, or where business rules change regularly.</li><li>Integration with other systems, especially in combination with event sourcing, where the temporal failure of one subsystem shouldn’t affect the availability of the others.</li></ul><p><strong>This pattern isn’t recommended when:</strong></p><ul><li>The domain or the business rules are simple.</li><li>A simple CRUD-style user interface and data access operations are sufficient.</li></ul><p>Consider applying CQRS to limited sections of your system where it will be most valuable.</p><h3>Let’s see how it looks in Code</h3><p>This part will not have “Code” but a a general low level design which helped me understand CQRS and implement it in my personal projects, and also in some of the projects that I have worked on — CQRS has really changed the way I write Microservices that are DDD.</p><pre>Controller Orders<br>- GET/Orders?id<br>- GET/Orders<br>- POST/Orders<br>- PUT/Orders<br>- DELTE/Orders?id</pre><pre>Controller Restaurant <br>- GET/Restaurant<br>- GET/Restaurant?id <br>- POST/Restaurant<br>- PUT/Restaurant<br>- DELTE/Restaurant?id</pre><pre>Controller Dish <br>- GET/Dish<br>- GET/Dish?id <br>- POST/Dish<br>- PUT/Dish<br>- DELTE/Dish?id</pre><pre>User <br>- GET/User?id</pre><p>Lets define the Query Models</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d4bb42955ec1545799c965cd8183538/href">https://medium.com/media/8d4bb42955ec1545799c965cd8183538/href</a></iframe><p>Here we can see that, we are defining the abstraction of all the queries that will be getting served to the Client</p><p>Lets define the Command Models</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb30a0cd2f9599093e407ecf46e4ce9c/href">https://medium.com/media/eb30a0cd2f9599093e407ecf46e4ce9c/href</a></iframe><p>Now the Interesting part, the handler — Lets take a look</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8caa6c5261b9136207699a513dbb2a8b/href">https://medium.com/media/8caa6c5261b9136207699a513dbb2a8b/href</a></iframe><h3>Integration into an existing application.</h3><p>CQRS is pretty flexible, here are some of my tips to adding CQRS and reaping its benefits</p><ol><li>Start with a single service or an API — this while not add performance gains but it will make the code more readable and easy to add new features and functionalities.</li><li>Separate your databases — One set (I said set, becuase in scale you would have sharded your DB) which is mainly used for writing, and one set for reading. You can say this is kinda like infra level CQRS?</li><li>Separate your services — A set of services that are only used to write into the database which are connected only with the “write set DB”, and the other to only read obviously connected with the “read set DB”, with this you have achieved a very level of separation. This structure is highly advantageous when you are using REST to write, update, delete and GraphQL to GET the data</li></ol><p>Somethings that CQRS goes well with</p><ol><li>Caching — this goes well becuase, you have models to write which are connected with services — so its easy to perform cache invalidation. Yeah I’d say its easy to invalidate as a bigger pro than performance</li><li>Event Sourcing — I will be writing about this soon</li></ol><h3>Footnotes</h3><ul><li>A good Doc from Microsoft — <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/cqrs">CQRS pattern — Azure Architecture Center | Microsoft Docs</a></li><li>An 6hr video on CQRS super cool, super long <a href="https://www.youtube.com/watch?v=whCk1Q87_ZI">GregYoung 8 CQRS Class — YouTube</a></li><li>A great article on CQRS with C# demo <a href="https://dzone.com/articles/a-developers-guide-to-cqrs-using-net-core-and-medi">A Developer’s Guide to CQRS Using .NET Core and MediatR — DZone Web Dev</a></li><li>A great article on CQRS with Golang <a href="https://threedots.tech/post/basic-cqrs-in-go/">Introducing basic CQRS by refactoring a Go project (threedots.tech)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3beae98c8bf0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basics of TensorFlow to get you started.]]></title>
            <link>https://arao1729.medium.com/basics-of-tensorflow-to-get-you-started-ad191048efa6?source=rss-a861eab7a8e2------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad191048efa6</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Aditya Rao]]></dc:creator>
            <pubDate>Sun, 09 Sep 2018 06:26:20 GMT</pubDate>
            <atom:updated>2018-09-10T07:03:13.640Z</atom:updated>
            <content:encoded><![CDATA[<p>TensorFlow is an Open-Source, Machine Learning framework to build, deploy and analyze your ML Models. This article is for someone who knows Deep Learning (Math and Theory), preferably gone through the <a href="https://www.deeplearning.ai/">deeplearning.ai</a> course or something similar.</p><p>Here you will get to understand the basic working of TensorFlow and how your Data in “Tensor” format, “Flows” through the computation graph. It always an advantage to think of your model visually on a computation graph.</p><p>Before jumping into the core, let&#39;s look at some of the Hyperparameters for the model, such as</p><ol><li>Learning Rate: This constant helps your Optimizer to compute new weights based on the weights of the previous iteration.</li><li>Batch Size: Batch size is a term used in machine learning and refers to the number of training examples utilized in one iteration.</li><li>Epochs: An epoch is one complete presentation of the data set, so if you have 1000 samples and 100 as your batch size, 1 Epoch will have 10 iterations.</li></ol><p>Generally, the input data is passed through the layers of our network, which gives a corresponding loss which is then reduced by our optimizer, we can then evaluate performance by training.</p><p>Every ML Project can be broken down into its smaller core components, such as</p><ol><li>Input(Data): Usually inputs are a set of data and their corresponding labels, defined using placeholders(promise values).</li><li>Layers: A layer is usually a composite of 2 or 3 components, A transform function (eg Dense, Convolution) and a Nonlinearity function also called as an activation function (eg Relu, Sigmoid, Tanh) and dropout, these components can be further broken down to their respective weights and biases.</li><li>Loss: Here we compute the cost, or we measure how inaccurate our model is, and compare it with the ground truth values.</li><li>Optimizer: An Optimizer is a function which we use to minimize the loss(cost) of our network, It generally uses some flavor of Gradient decent or in more practical scenarios uses Stochastic Gradient Descent, wrapped as Adam or Adagrad or RMSProp</li><li>Evaluation: Is this section we calculate the correct values predicted and find out the accuracy of our model.</li><li>Training: In the above steps we only construct the network and define the parameters, here we execute the training in batches using the batch size and then push the data to the model to train.</li></ol><p>Let&#39;s look at the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/776b873e36bfca00b7b64bdaaca320e1/href">https://medium.com/media/776b873e36bfca00b7b64bdaaca320e1/href</a></iframe><p>The general takeaway from this blog is the different components of a model, also for beginners when going through research papers look for these 6 parts, as they will help in understanding the paper.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad191048efa6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>