<?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 David Nissimoff on Medium]]></title>
        <description><![CDATA[Stories by David Nissimoff on Medium]]></description>
        <link>https://medium.com/@david.nissimoff?source=rss-b636953fa480------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*fPvHuTZ9OcbxvCS5oIrDMA.png</url>
            <title>Stories by David Nissimoff on Medium</title>
            <link>https://medium.com/@david.nissimoff?source=rss-b636953fa480------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 08:10:50 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@david.nissimoff/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[Next.js meets ASP .NET Core — a story of performance and love at long tail]]></title>
            <link>https://medium.com/@david.nissimoff/next-js-meets-asp-net-core-a-story-of-performance-and-love-at-long-tail-41cf9231b2de?source=rss-b636953fa480------2</link>
            <guid isPermaLink="false">https://medium.com/p/41cf9231b2de</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[dotnet]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[aspnetcore]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[David Nissimoff]]></dc:creator>
            <pubDate>Tue, 31 May 2022 15:12:47 GMT</pubDate>
            <atom:updated>2022-05-31T15:12:47.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>Next.js meets ASP .NET Core — a story of performance and love at long tail</h3><p>If you are a frontend developer, chances are you have heard of or you actively use <a href="https://nextjs.org/">Next.js</a>. And if you are a backend developer (or not), surely Node.js more than rings a bell. Afterall, if one wants to host a Next.js app, clearly one would do it on Node.js or some cloud provider that runs it on your behalf, right? Well…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fiL3qwTguEVjCCRBieCVOQ.gif" /><figcaption>Building the Next.js web app then running the ASP .NET Core server</figcaption></figure><h4>A hint of where we are headed…</h4><blockquote>Measured throughput was ~6–7x greater on ASP .NET Core; P99 latency was ~2–4x better on ASP .NET Core</blockquote><p>Is it a fair comparison? Not really. Read on to learn more…</p><p>Associated Github repo: <a href="https://github.com/davidnx/NextjsStaticHosting-AspNetCore">davidnx/NextjsStaticHosting-AspNetCore: Next.js apps on ASP .NET Core without Node.js (github.com)</a></p><h4>A step back before we get to the fun part…</h4><p>The first thing to know about modern web app frameworks like Next.js is that web page interactivity does not require an interactive server with dynamic api’s. One powerful capability of Next.js, <a href="https://nextjs.org/docs/advanced-features/static-html-export">Static HTML Export</a>, compiles your entire web app to simple files that can be served from anywhere (<a href="https://javascript.plainenglish.io/deploy-your-next-js-app-on-github-pages-using-the-github-action-525271137409">examples</a> <a href="https://medium.com/bb-tutorials-and-thoughts/how-to-host-a-next-js-static-website-on-azure-515814076624">abound</a> which only serves static files and no dynamic content — yet the resulting pages can be complete dynamic web apps).</p><blockquote>Web page interactivity does not require an interactive server with dynamic api’s</blockquote><p>In fact, one of the tricks Next.js employs to achieve optimal page load performance, SSG (<a href="https://nextjs.org/learn/seo/rendering-and-ranking/rendering-strategies">Static Site Generation</a>), consists of statically generating content at build time — HTML, embedded CSS and all — and just serving this when a client loads the page. This has benefits across the board: pages load faster; Search Engines gain better visibility into the actual rendered content; etc.</p><h4>Why Node.js?</h4><p>There are scenarios where the final contents cannot be produced at build time. This includes web apps leveraging SSR (<a href="https://nextjs.org/docs/basic-features/pages#server-side-rendering">Server-Side Rendering</a>) or other Next.js features listed under Static HTML Export <a href="https://nextjs.org/docs/advanced-features/static-html-export#unsupported-features">unsupported features</a>. In those cases, there’s no way but to render the web app server-side at request time, and then serve the final contents to the client. Node.js is the technology that enables running the same JavaScript, or portions of it, that would run on the client, but on the server.</p><h4>But do we need SSR?</h4><p>Software Engineering is often about finding the right balance among competing trade-offs. In many cases, SSR may absolutely be the right solution. This article is for all other cases. Mind you, this is hardly a tough constraint. A lot can be done with fully static content! Recall for a moment that when you install an app on your mobile device, a static app package is installed on your device. A statically exported Next.js app isn’t much different.</p><blockquote>When you install an app on your mobile device, a static app package is installed on your device. A statically exported Next.js app isn’t much different</blockquote><h3>Fine. Let’s host static files. Are we done now?</h3><p>Almost. There is one additional concern we need to deal with, and that is <a href="https://nextjs.org/docs/routing/dynamic-routes">Dynamic Routes</a>.</p><p>Imagine a Next.js application consisting of the following pages:</p><ul><li>/pages/index.js</li><li>/pages/post/[pid].js</li></ul><p>When statically exported to HTML using npx next export, the exported output will contain the following entry-point HTML files:</p><ul><li>/out/index.html</li><li>/out/post/[pid].html</li></ul><p>When a browser issues a request for /, the server is expected to return the contents of /out/index.html. Similarly, a request for /post/123 is supposed to return the contents of /out/post/[pid].html. As long as the appropriate initial HTML is served for the incoming request paths, Next.js takes care of the rest, and will rehydrate the page on the client-side providing full React and interaction capabilities.</p><p>However, if the wrong page is served (e.g., if /out/index.html were served on a request for /post/123), rehydration won&#39;t work (by design!). The client will render the contents of /pages/index.js page even though the URL bar will say /post/123, and it will NOT rehydrate the contents that were expected — code running in the browser at that time in fact would not even know that it was supposed to be showing the contents of a different page.</p><h4>SSG-safe rehydration</h4><p>Beware of an important caveat with this approach. Next.js expects, reasonably so, that the first render of the page JavaScript should produce the exact same tree as had been produced statically. This poses a challenge when dynamic content is to be rendered for dynamic routes. Imagine for example that the page contents will include an h1 tag with contents that include a parameter specified via a dynamic route. You must be careful to ensure the tree is consistent with the statically generated contents on first render.</p><p>Luckily, this is easy to achieve by creating a state variable that gets updated on mount with useEffect. The sample app showcases exactly this scenario (<a href="https://github.com/davidnx/NextjsStaticHosting-AspNetCore/blob/2262b5ca7db550b7d21efa1ad013121a9c533ce8/samples/ActualNextjsApp/ActualNextjsApp.Client/pages/post/%5BpostId%5D.tsx#L8-L13">source</a>).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/56a39dba16984a48769989b40a296e3a/href">https://medium.com/media/56a39dba16984a48769989b40a296e3a/href</a></iframe><h4>How do we ensure the right contents are served?</h4><p>It’s quite simple actually. We just need the web server to understand what routes should map to which statically-generated files. Recapping the previous example, a request to /post/123 needs to produce the contents of /out/post/[pid].html. As long as routes are created with the right patterns, everything else falls into place.</p><p>Now all we need is a high performance Web Server with custom routing capabilities…</p><h4>ASP .NET Core to the rescue</h4><p><em>Full disclosure: No, I didn’t just randomly pick ASP .NET Core. I happen to work for Microsoft where we use ASP .NET Core extensively for high scale, mission critical web services that power multi-billion dollar businesses. The developer experience and performance make it a great choice for such applications. That said, this is a personal project and unrelated to my day-to-day job.</em></p><p><a href="https://github.com/dotnet/aspnetcore">ASP .NET Core</a> is <a href="https://www.techempower.com/benchmarks/">among</a> the best performing general-purpose web servers in wide use today, and Microsoft has been <a href="https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-core-3-0/">investing</a> <a href="https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-5/">heavily</a> <a href="https://devblogs.microsoft.com/dotnet/performance-improvements-in-net-6/">on</a> <a href="https://devblogs.microsoft.com/dotnet/performance-improvements-in-aspnet-core-6/">pushing</a> this further. It being open-source and cross-platform makes it is a natural choice to host modern web apps at scale.</p><h4>Show me the code</h4><p>It’s about time you asked: <a href="https://github.com/davidnx/NextjsStaticHosting-AspNetCore">https://github.com/davidnx/NextjsStaticHosting-AspNetCore</a>. It is also available as a <a href="https://www.nuget.org/packages/NextjsStaticHosting.AspNetCore">Nuget package</a>.</p><p>This package works by transforming the statically compiled Next.js output directory structure into ASP .NET Core Endpoints (see: <a href="https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-6.0">Routing in ASP .NET Core</a>). Dynamic Routes are converted to parameterized route templates. To illustrate, page /pages/post/[pid].js from the previous example gets represented by a new Endpoint with route template/post/{pid} which ASP .NET Core understands. Requests matching this endpoint serve the desired file with a standard StaticFileMiddleware (<a href="https://github.com/davidnx/NextjsStaticHosting-AspNetCore/blob/2262b5ca7db550b7d21efa1ad013121a9c533ce8/src/NextjsStaticHosting.AspNetCore/Internals/NextjsEndpointDataSource.cs#L192">source</a>).</p><h4>Local development experience</h4><p>Next.js offers HMR (Hot Module Replacement), which significantly speeds up development. To maintain full fidelity to the usual npm run dev experience, this project deliberately makes no attempt to replace it. Instead, the library is configurable to run in development mode, such that it forwards requests appropriately to the local Next.js dev server with full fidelity by using <a href="https://github.com/microsoft/reverse-proxy">YARP</a> (<em>“A toolkit for developing high-performance HTTP reverse proxy applications”</em>). The <a href="https://github.com/davidnx/NextjsStaticHosting-AspNetCore/tree/master/samples/ActualNextjsApp">sample client-server app in the repo</a> shows how this is configured.</p><h3>Is it any faster? Benchmark time</h3><p>Measured on Windows 11 version 21H2 (OS Build 22000.675) on an AMD Ryzen 9 5900HX using latest LTS releases of .NET 6 (6.0.5) and Node.js (16.15.0) as of 5/27/2022. Tests were run against localhost on raw HTTP using Apache Bench Version 2.3 Revision: 1879490 as the test client.</p><p>The ASP .NET Core project was published in Release configuration and executed without custom tweaks. The Next.js app was run with npm run start without custom tweaks (see: <a href="https://nextjs.org/docs/deployment#nodejs-server">docs</a>). Each scenario was run 3 times, and the median run is shown.</p><p><strong>Measured throughput was ~6–7x greater on ASP .NET Core; P99 latency was ~2–4x better on ASP .NET Core.</strong></p><h4>Scenario 1: 10 concurrent, 50k requests</h4><p>Command line: ab -c 10 -n 50000 -k <a href="http://localhost:PORT/post/1">http://localhost:PORT/post/1</a></p><pre> Hosting stack    Avg (ms)    P99 (ms)<br>---------------- ----------- ------------<br> ASP .NET Core    0.469       1<br> Node.js          3.355       5</pre><h4>Scenario 2: 100 concurrent, 100k requests</h4><p>Command line: ab -c 100 -n 100000 -k <a href="http://localhost:PORT/post/1">http://localhost:PORT/post/1</a></p><pre> Hosting stack    Avg (ms)    P99 (ms)<br>---------------- ----------- ------------<br> ASP .NET Core    4.957       22<br> Node.js          29.652      41</pre><h4>Is this a fair comparison?</h4><p>Not really, for a few reasons. But it is still informative:</p><ul><li>The capabilities of the two stacks are not equivalent, and the ASP .NET Core hosting stack enabled by this project does not support SSR content. To a large degree, we are comparing apples and oranges. On the other hand, entire apps can be built without needing SSR. In those cases, the additional capabilities of running in Node.js are unused</li><li>Only measuring the time to load the HTML for a page. Loading other static content (js, css, images, etc.) may account for longer delays in observed page load performance in practice, and those aren’t taken into account in these tests</li><li>Not necessarily following best practices for production hosting, though the setup followed the official guidance for both Next.js and ASP .NET Core without additional tweaks in either</li><li>Run on Windows, whereas each stack could exhibit different perf characteristics on a different OS</li></ul><h3>Where do we go from here?</h3><p>Anywhere! Or nowhere, really… If you are running your Next.js apps on Node.js and/or the cloud provider of your choice, you likely have no reason whatsoever to change.</p><p>I expect this article and associated code to be most useful in the following cases:</p><ul><li>If you already have a backend written on .NET technologies, and you are looking to add a modern React-based web app to your solution. Instead of spinning up a new (micro-?)service to host Node.js, perhaps you’d be interested in hosting the web app alongside your existing ASP .NET Core services.</li><li>If you already host a Next.js web app and have no need for dynamic server-generated content and you want to extract the last drop of performance and/or reduce your cloud spend</li><li>Simply learning more about how Next.js Static HTML Export works</li><li>Simply learning more about <a href="https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-6.0">ASP .NET Core</a> and <a href="https://github.com/microsoft/reverse-proxy">YARP</a></li></ul><p>Thoughts? Questions? Concerns? Leave a comment and/or create issues on Github and I will do my best to address them. Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=41cf9231b2de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Cosmos DB like a pro (minimize cost, maximize productivity)]]></title>
            <link>https://medium.com/@david.nissimoff/azure-cosmos-db-like-a-pro-minimize-cost-maximize-productivity-24dfee205c0?source=rss-b636953fa480------2</link>
            <guid isPermaLink="false">https://medium.com/p/24dfee205c0</guid>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cosmosdb]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[nosql]]></category>
            <dc:creator><![CDATA[David Nissimoff]]></dc:creator>
            <pubDate>Fri, 12 Oct 2018 15:21:02 GMT</pubDate>
            <atom:updated>2018-10-12T19:18:35.605Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure Cosmos DB is a multi-modal, fully-managed database service with an interesting pay-per-provisioned-throughput pricing. In practice, the general implication is that applications with higher scalability needs can pay more to attain required performance, and Azure’s infrastructure adapts accordingly. It offers great predictability in both cost and performance, both great attributes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*VTUuCewA-VJ0En8clubdBw.png" /></figure><p>While simple on the surface, one soon realizes that there are application-level architectural decisions that affect various trade-offs, and there isn’t always a single optimal or obvious solution across the 3 dimensions of <strong><em>a)</em></strong> high developer productivity; <strong><em>b)</em></strong> high performance; and <strong><em>c)</em></strong> low cost. This article explores some of those trade-offs and presents a strategy that optimizes <em>bang for the buck</em> in many cases. Particularly so for small deployments.</p><p>The title of this article uses the term “Azure Cosmos DB” as a verb. Hopefully it will help you “Azure Cosmos DB like a pro” too 😄.</p><h3>API choice (SQL / Mongo / Table / Gremlin / Cassandra)?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/574/1*_bHNu8mZchQu-gPCLdo61g.png" /></figure><p>Unique to Cosmos DB is its support for different API models. The official documentation doesn’t seem to proclaim a preferred choice, but there are caveats to be aware of:</p><ul><li>You choose the API when creating a Cosmos DB account, and you cannot change it after (unless you create another account)</li><li>Many features are only available with the SQL API (e.g. ability to write and run custom code in Cosmos DB’s servers — modern stored procedures in JavaScript)</li><li>SQL in Cosmos DB isn’t really what you might know (and perhaps fear) as SQL. They have similarities, but Cosmos DB’s approach is novel and rather clever. It remains faithful to NoSQL ideas despite the name.</li></ul><blockquote><strong>Conclusion: </strong>Cosmos DB’s SQL isn’t your old SQL. <strong>Choose SQL API</strong> if you’re building something new, and don’t look back.</blockquote><h3>A note on terminology</h3><p>Azure Cosmos DB defines generalized terms that work with its various API models, which can create some confusion. Since we are going ahead with the SQL API, keep the following in mind when looking at Azure’s <a href="https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-resources">documentation</a>:</p><ul><li><strong>Collection == Container:</strong> a collection of JSON entries. Analogous to a table in a traditional RDBMS</li><li><strong>Database: </strong>a group of one or more <em>collections</em></li></ul><h3>Provisioning granularity — Collection Vs. Database</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/577/1*4Aa7Mw5AuMmOzTqoNRQMQw.png" /></figure><p>When creating a database, you can provision (and pay for) throughput at the database level or at the collection level (default).</p><ul><li><strong>Database-level:</strong> Provisioned throughput is made available to all collections in the database. If one collection is more active than another, you’ll achieve higher density and more efficient use of your provisioned throughput. On the flip side, you can experience noisy <a href="https://en.wikipedia.org/wiki/Cloud_computing_issues#Performance_interference_and_noisy_neighbors">neighbor issues</a> (one collection being too active takes away throughput from other collections). <strong>Minimum provisioned throughput 10,000 RU/s ($584.00/month*)</strong></li><li><strong>Collection-level</strong> (default): Provisioned throughput applies to a single collection. Mitigates noisy neighbor problems, but leads to worse utilization of provisioned throughput (idle time of one collection cannot be used by others). <strong>Minimum provisioned throughput 400 RU/s ($23.36/month*)</strong></li></ul><blockquote>* Storage is billed separately and costs the same for either choice of granularity ($0.25/GB/month*)<br>* Price estimates come from the <a href="https://azure.microsoft.com/en-us/pricing/details/cosmos-db/">Cosmos DB Pricing page</a> considering deployments in West US, single-master option, noted on 10/10/2018</blockquote><p>The trade-off, therefore, is whether to use <em>Database-level</em> provisioning (which can lead to better resource utilization, but has a high starting cost) or <em>Collection-level</em> (which is cheaper to start with). <strong>Or perhaps can we meet in the middle?</strong></p><h3>Best of both worlds?</h3><p>The idea here is rather simple. We leverage the fact that Cosmos DB is a schema-less database and we will store disparate item types into a single <em>collection</em>. For example, a blogging system could use these objects:</p><pre>Record 1: {&quot;kind&quot;: &quot;author&quot;, &quot;name&quot;: &quot;David&quot;, &quot;id&quot;: &quot;123&quot; }<br>Record 2: {&quot;kind&quot;: &quot;blogPost&quot;, &quot;authorId&quot;: &quot;123&quot;, &quot;text&quot;: &quot;hello&quot; }<br>...</pre><p>Because of Cosmos DB’s internal indexes, we can run efficient queries looking for a specific kind. We thus effectively create a concept of <em>sub-collections</em> in Cosmos DB, partitioned by their kind. We can now use the inexpensive <strong>Collection-level provisioned throughput</strong>, and the throughput will be shared among all <em>sub-collections</em>. Additionally, small applications can get by at the lowest possible cost of 400 RU/s and there are no constraints on the complexity of their data organization. At this price point, and with all the power of Cosmos DB, this is a quite compelling value proposition.</p><blockquote><strong>Conclusion: </strong>when creating your database, <strong>do not</strong> enable database-level provisioned throughput. We can use sub-collections by using a string field kind in each record to organize our data.</blockquote><h3>Creating a collection</h3><p>Recap so far:</p><ol><li>You’ve created a Cosmos DB account with <strong>SQL API</strong>.</li><li>You’ve created a database that does not have database-level provisioned throughput</li><li>We now need to create a collection where all the data will go</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/486/1*AQWHJW9OSXRZuxDjllGknQ.png" /></figure><p>When creating the collection, you are asked whether to use <strong>Fixed capacity (10GB)</strong> or <strong>Unlimited</strong>. Again, there are caveats to be aware of:</p><ul><li>Once you’ve created the collection, you cannot change this (short of recreating the collection)</li><li><strong>Fixed (10GB) </strong>is the default and is the easier way to start. It allows you to go down to the minimum provisioned throughput of 400 RU/s</li><li><strong>Unlimited </strong>requires a minimum provisioned throughput of 1000 RU/s ($58.40/month*), and additionally requires you to specify a partitioning key to help shard your data across multiple servers</li></ul><blockquote><strong>Conclusion:</strong> <em>Fixed (10 GB)</em> should be a good initial choice. Just beware that you may have to recreate the collection should you need to change this later.</blockquote><h3>Developer productivity</h3><p>Sample code for this article is on <a href="https://github.com/davidnx/CosmosDbSubCollections">Github</a>. You can copy the code or reference the Nuget package <a href="https://www.nuget.org/packages/CosmosDbSubCollections">CosmosDbSubCollections</a> in your project. Creating a sub-collection involves the following steps:</p><ol><li>Create a class to represent the entity, deriving from the provided <a href="https://github.com/davidnx/CosmosDbSubCollections/blob/master/CosmosDbSubCollections/EntityBase.cs">EntityBase</a> class. This base class in turn derives from Microsoft.Azure.Documents.Resource and adds the string Kind property.</li><li>Create a class that performs basic operations for the entity, deriving from <a href="https://github.com/davidnx/CosmosDbSubCollections/blob/master/CosmosDbSubCollections/EntityClientBase.cs">EntityClientBase&lt;TEntity&gt;</a>. The base class already takes care of the low level operations (ListAllAsync,UpsertAsync) and you can add additional methods that make sense to your particular entity (for example, see <a href="https://github.com/davidnx/CosmosDbSubCollections/blob/master/CosmosDbSubCollections.Demo/EntityClients/BlogPostEntityClient.cs#L17">BlogPostEntityClient.ListByAuthorAsync</a> in the provided code).</li><li>Update your <a href="https://github.com/davidnx/CosmosDbSubCollections/blob/master/CosmosDbSubCollections.Demo/DemoAdapter.cs#L33">DB adapter class</a> to maintain an instance of the class mentioned in (2) above.</li><li><em>(optional)</em> Create interfaces for (2) and (3) to facilitate unit testing the rest of your application (you can then provide mock / fake implementations of those interfaces in your tests, instead of the actual database client).</li></ol><p>Considering the alternatives, this is quite straightforward and scales well to large numbers of entities for complex applications. Additionally, it results in efficient Linq queries that get executed in Cosmos DB and, as mentioned, enables easy unit testing.</p><p>Once it’s all said and done (<a href="https://github.com/davidnx/CosmosDbSubCollections/blob/master/CosmosDbSubCollections.Demo/Program.cs#L27">code</a>), usage is quite clean:</p><pre>var client = new DocumentClient(...); // Normal init<br>var adapter = new DemoAdapter(client, dbName, collectionName);</pre><pre>var allAuthors = await adapter.Authors<br>    .ListAllAsync(cancellationToken);</pre><pre>var firstAuthorPosts = await adapter.BlogPosts<br>    .ListByAuthorAsync(<br>        allAuthors[0].Id,<br>        cancellationToken);</pre><p>Compare this vs. alternatives where one massive class might implement tens or hundreds of individual methods for all CRUD operations against each type of entity used.</p><p>The sample also shows how to keep track of RU’s charged per request, and keeps a running sum of how many have been consumed in a session, as well as total number of requests. The proposed design makes it easy to have a centralized place to aggregate interesting data about Cosmos DB performance, and could be easily extended to also keep track of latencies, etc.</p><pre>Console.WriteLine($&quot;Charge: {adapter.TotalCharge} RU&#39;s&quot;);<br>Console.WriteLine($&quot;Requests: {adapter.TotalRequests}&quot;);</pre><h3>Summary</h3><ul><li>Cosmos DB offers a compelling value proposition, even for small deployments. But the application has to be designed to leverage it appropriately</li><li>High developer productivity, high performance, and low cost are achievable in tandem</li><li>The provided sample code shows one way to organize the classes cleanly and minimizing boiler plate.</li></ul><p>That’s it for now. If you see other ways to improve this, send comments (or PR’s 😄). All feedback is welcome.</p><blockquote>Full disclosure: I am a Software Engineer at Microsoft, but not in the Azure Cosmos DB team. My experience with the product has been mostly on my spare time and for personal projects.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24dfee205c0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>