<?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 Chris Smith on Medium]]></title>
        <description><![CDATA[Stories by Chris Smith on Medium]]></description>
        <link>https://medium.com/@chriss_37989?source=rss-cf80862eb3db------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zAGWlUK7_uP8H_FqZZuf7Q.jpeg</url>
            <title>Stories by Chris Smith on Medium</title>
            <link>https://medium.com/@chriss_37989?source=rss-cf80862eb3db------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 03:04:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@chriss_37989/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[Labs Notes: Exploring GraphQL for Web APIs — Introduction and Thoughts]]></title>
            <link>https://medium.com/mission-data-journal/labs-notes-exploring-graphql-for-web-apis-introduction-and-thoughts-a153910657ec?source=rss-cf80862eb3db------2</link>
            <guid isPermaLink="false">https://medium.com/p/a153910657ec</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Chris Smith]]></dc:creator>
            <pubDate>Wed, 03 Aug 2022 18:30:50 GMT</pubDate>
            <atom:updated>2022-10-31T15:52:26.901Z</atom:updated>
            <content:encoded><![CDATA[<h3>Labs Notes: Exploring GraphQL for Web APIs — Introduction and Thoughts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/1*m4Lk-7cvR8xMvPVD_7Tb8g.png" /></figure><p>Web APIs are everywhere and, as developers, we generally spend a great deal of time building and updating them. While the most common implementations are REST APIs, there are alternatives that you might not have experimented with. The purpose of this article is to introduce one of those alternatives, <a href="https://graphql.org/">GraphQL</a>.</p><h3>What is GraphQL?</h3><p>GraphQL is an open-source data query and manipulation language paired with a cross-platform server-side runtime that provides a foundation for scalable and efficient communication for web applications. Despite its name, it is not a replacement for database systems. Instead, it provides a system for web clients to request or manipulate API data by specifying the objects and fields needed, while the server-side runtime interfaces with the database.</p><h3>Is it like a REST API?</h3><p>There are similarities between REST and GraphQL. Both cover machine-to-machine communication, most often between a web app client and a backend server. Both often use JSON to communicate information in requests. However their capabilities and goals are different. GraphQL behaves like a queryable hierarchical, strongly typed data model. REST is a looser and more general set of principles for web API design. GraphQL is an application-layer protocol powered by a server side engine, while REST specifies an architectural style.</p><p>Let’s consider a scenario where we want to fetch a blog writer’s name, the title of all the posts they’ve written, and the name of their last three followers.</p><p>A REST API receives requests and sends responses over the HTTP protocol. It uses HTTP methods — like GET, POST, PUT and DELETE — with URL patterns and parameters to indicate an action. Only one step can be executed per request, and the data returned is typically in a fixed format. A typical REST API would require the following steps to retrieve the data needed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2J23YXujfOZDUWSE" /></figure><p>It takes three requests to get the desired data, and there are unnecessary data elements. Let’s talk through this a bit.</p><p>The request to /users/&lt;id&gt; gives us some basic information about the user but doesn’t give everything needed. This scenario is called <em>under fetching</em> and forces the client to make additional calls elsewhere to get the required data.</p><p>What if we have a list of users and need the same information for each user? We’d need to call the /users/&lt;id&gt;/posts and /users/&lt;id&gt;/followers endpoints for each user record. This scenario is the <em>n+1</em> problem and can quickly get out of hand as the user list grows.</p><p>What about all the unnecessary data returned by each of the three endpoints? This scenario is called <em>over fetching</em>, which causes increased data size and impacts the cost and perceived performance.</p><p>How can we solve these issues? We could create REST endpoints for each use case — this is a reactive approach and could be challenging to scale to customer demand. Let’s look at how GraphQL solves these issues.</p><p>While GraphQL also receives requests and sends data over the HTTP protocol, it uses a limited range of HTTP methods — like GET or POST — and the client can request one or more actions or relationships from a single request endpoint. The request payload specifies the exact data needed, and the returned data is always in a JSON format. An equivalent GraphQL flow for the REST API user example would look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mbFUcI009jzwn-gn" /></figure><p>This is an efficient approach: the client defines what’s needed, makes one request to get all the data required, and the server returns only the data requested.</p><p>Again, while there are similarities between REST API and GraphQL, the capabilities are very different.</p><p>Let’s explore this more in the next section.</p><h3>Contracts and Type Safety with GraphQL Schemas</h3><p>A major problem with JSON-based services is the lack of a strict built-in contract regarding what the client can expect and the exact data type for each object or property.</p><p>Contracts in most JSON-based REST APIs consist of documentation and team communication, which aren’t runtime guarantees. This approach to contracts can be subject to miscommunication and have no automated validation to ensure adherence.</p><p>JSON is also limited by the amount of native data types — strings, numbers, booleans, arrays, general objects, and <em>null</em> — and cannot be extended to provide additional universal type-checked data types.</p><p>GraphQL solves these problems by using an extensible and strong type-based schema to define the capabilities of the API. Schemas are defined using the Schema Definition Language (SDL). SDL has a straightforward syntax and allows for a concise schema. A GraphQL endpoint’s schema is available to both the server and the client, and each request and response is validated before requesting or sending data.</p><p>A GraphQL schema for our blog writers example might look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dFC0rYq2Gp4zlbsP.png" /></figure><p>There’s a lot to unpack in this example. While it only scratches the surface, the main points here are:</p><ul><li>The type Query is a particular type of object. The Query object contains all the top-level entry points for querying data – like getUser(id: ID!).</li><li>SDL allows for adding comments in-line to explain their behavior or usage. While my example shows a comment for the getUser(id: ID!) entry point, you can add comments anywhere.</li><li>Entry points can take parameters and return data. The parameters and returned data always have data types.</li><li>The other types — User, Post, Address, and PostComments – define the service’s objects. Each object lists the fields, and each field is associated with a data type.</li><li>SDL defines some base of data types — like ID and String – called scalars. You can define custom scalar types. I’ve created the custom scalar types ISO8601Date and ISO8601DateTime to indicate these types have a particular format.</li><li>An entry point or field can return an array of values, denoted as [].</li><li>The presence of the “!“ character means that the field or the return value will not be null.</li><li>Object fields can have arguments — like followers(last: Int) – allowing clients to filter or limit subfields.</li></ul><p>Each GraphQL service has only one schema, and that schema defines the actions, objects, relationships, and data types the client should expect.</p><p>What about object and data reuse?</p><p>You may want to reference a service’s objects outside a single service; the User object is a great example. One possible solution is duplicating all the user data between GraphQL services, but that approach introduces tight coupling and adds complexity. Using a distributed GraphQL architecture to combine multiple GraphQL schemas, there’s no need to duplicate user data or introduce tight coupling. Let’s look at how this works in the next section.</p><h3>Combining Multiple GraphQL Schemas</h3><p>You <em>could</em> create one <a href="https://en.wikipedia.org/wiki/Monolithic_application">monolithic application</a> instead of juggling numerous GraphQL services. This approach eliminates needing to combine various schemas; however, your use case may require a microservice approach to scale specific components of your system or allow for the <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a> design principle.</p><p>For the latter, we’ll look at the <a href="https://www.apollographql.com/docs/federation/">Apollo Federation</a> (federation) distributed GraphQL architecture.</p><p><em>There are many distributed GraphQL architectures and techniques to accomplish this feat — </em><a href="https://www.graphql-tools.com/docs/schema-merging"><em>schema merging</em></a><em>, </em><a href="https://www.graphql-tools.com/docs/schema-stitching/stitch-combining-schemas"><em>schema stitching</em></a><em>, </em><a href="https://www.graphql-tools.com/docs/schema-wrapping"><em>schema wrapping</em></a><em>, and federation. I’ll focus on the federation approach for this article since it fits the needs of my example.</em></p><p>Federation introduces a gateway — called a supergraph gateway — that combines multiple GraphQL service schemas into a unified graph, or supergraph. Each GraphQL service registered with the supergraph gateway is called a subgraph service, and each subgraph service’s schema is combined into a supergraph served by the supergraph gateway. Clients interact with the supergraph gateway, and the supergraph gateway routes requests to the appropriate subgraph service.</p><p>Let’s split our blog writers schema example into two subgraphs — a Users subgraph that handles User and Address and a Posts subgraph that handles Post and PostComment. We want the web clients to interact with the supergraph gateway, and the supergraph gateway will forward requests to the relevant subgraph once they are registered.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/0*br2y0Qn0UPrDKHNo" /></figure><p>This approach enables a lot of flexibility with architecture design. Let’s look at how our original GraphQL schema could be split up per microservice.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yy_XqxmDfDY5ePGz.png" /></figure><p>In this example, we’re splitting our microservices by domain — one microservice to handle user-specific data and another to handle post and post comment data. While the format is similar to our previous example, there are a few new concepts.</p><ul><li>In the Users Subgraph, you’ll see that the User type now has a @key(fields: &quot;id&quot;) attribute. The <a href="https://www.apollographql.com/docs/federation/federation-spec/#key">key</a> directive indicates that User values can be uniquely identified by the “id” value and enables the fetching of user records from external references.</li><li>The Posts Subgraph has a User type as well. However, its version is simplified and contains only the user’s ID and a reference to the user’s posts. We’re using the <a href="https://www.apollographql.com/docs/federation/v1/entities/#extending-entities">extends</a> keyword to <em>extend</em> the Users Subgraph User type to include the posts: [Post!]! attribute.</li><li>And finally, the <a href="https://www.apollographql.com/docs/federation/federation-spec/#external">external</a> directive marks the Posts Subgraph’s User.id attribute as owned by a separate service. The Posts Subgraph microservice will only need to supply the User.id value. The supergraph gateway will query the Users Subgraph microservice to provide the remaining user data before returning the result to the web client.</li></ul><p>This is advantageous because the developers working on the Posts microservice only have to store the user’s ID, the storage of the other user attributes isn’t duplicated, and the web client only needs to make one request.</p><h3>Developer Thoughts</h3><p>GraphQL offers a lot of value by reducing bandwidth requirements and speeding up web client requests. However, nothing is ever a silver bullet that will solve every problem, and GraphQL implementations can require a lot of planning. I don’t recommend running out and replacing your existing REST APIs with a GraphQL implementation.</p><p>That said, GraphQL is a great choice when you need to support different client views, have to be efficient with bandwidth and data storage, need to scale by concern, and want to combine multiple microservices into one endpoint seamlessly.</p><p><strong>Benefits:</strong></p><ul><li>Reduced bandwidth requirements — clients request only what’s needed</li><li>Reduces or eliminates the need for separate <a href="https://docs.microsoft.com/en-us/azure/architecture/patterns/backends-for-frontends">Backend for Frontend</a> supplemental applications</li><li>Encourages <a href="https://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a></li><li>Wide language support, as listed on the <a href="https://graphql.org/code/">GraphQL Language Support</a> page</li><li>Open source and commercial support options are available</li></ul><p><strong>Drawbacks:</strong></p><ul><li>Steep learning curve</li><li>Requires additional planning when combining multiple services</li><li>Complex and dynamic data structures are more challenging to cache</li></ul><h3>Conclusion</h3><p>GraphQL provides functionality for defining an extensible and strong type-based schema to define the capabilities of an API. The schema is self-documenting and communicates to the user what to expect and how to use it. Requests and responses are validated to ensure that the action, requested data, and returned data match what’s available in the schema. Users specify the exact objects and fields needed from the entry points and only that data is returned.</p><p>Multiple GraphQL services can be combined and served from a single URL through various techniques. We briefly covered how this would work using an Apollo Federation (federation) distributed GraphQL architecture.</p><p>I’ve only scratched the surface of what GraphQL can provide and how it works. However, you should have a basic idea of what GraphQL is and how it compares to a REST API.</p><figure><a href="https://cta-redirect.hubspot.com/cta/redirect/2399711/2c85370d-6a82-4f11-aee4-b5d3a2964e61"><img alt="Teaser graphic with text that states “Transform your business with innovative digital products.”" src="https://cdn-images-1.medium.com/max/1024/1*DIcGoMJBna5RsxVE-qmrEw.jpeg" /></a></figure><h3>About Mission Data:</h3><p>We’re designers, engineers, and strategists building innovative digital products that transform the way companies do business. Learn more: <a href="https://www.missiondata.com/">https://www.missiondata.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a153910657ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mission-data-journal/labs-notes-exploring-graphql-for-web-apis-introduction-and-thoughts-a153910657ec">Labs Notes: Exploring GraphQL for Web APIs — Introduction and Thoughts</a> was originally published in <a href="https://medium.com/mission-data-journal">Mission Data Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lab Notes: Looking at NestJS for Web Apps — Overview, Performance, Thoughts]]></title>
            <link>https://medium.com/mission-data-journal/lab-notes-looking-at-nestjs-for-web-apps-overview-performance-thoughts-433f62fe4f67?source=rss-cf80862eb3db------2</link>
            <guid isPermaLink="false">https://medium.com/p/433f62fe4f67</guid>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[labs]]></category>
            <dc:creator><![CDATA[Chris Smith]]></dc:creator>
            <pubDate>Tue, 22 Mar 2022 21:15:35 GMT</pubDate>
            <atom:updated>2022-10-31T16:17:11.475Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lab Notes: Looking at NestJS for Web Apps — Overview, Performance, Thoughts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*dVBZFO-yDFkzkb-UvKgA-A.png" /></figure><p>This article begins a series of deep dives exploring the practicalities and pitfalls of using the NestJS framework for building modern Node.js server-side web applications. This first installment provides an overview of NestJS, discusses performance, and wraps up with thoughts from a developer perspective.</p><h3>What is NestJS?</h3><p><a href="https://nestjs.com/">NestJS</a> is an opinionated server-side Node.js framework that provides an out-of-the-box application architecture for creating highly testable, scalable, loosely coupled, and easily maintainable applications.</p><p>Just how opinionated is NestJS?</p><p>It follows the “​​<a href="https://en.wikipedia.org/wiki/Convention_over_configuration">convention over configuration</a>” software design paradigm, <em>often</em> allowing developers to create more things in less time. This paradigm advocates guiding developers to use specific tools and coding approaches to decrease the number of decisions developers have to make without necessarily losing flexibility or repeating code.</p><p>That sounds great, but no framework is a perfect fit. Let’s look at some benefits and drawbacks.</p><h3>Benefits</h3><ul><li>Low memory footprint</li><li>Can handle a lot of concurrent requests</li><li>Prefers the use of TypeScript</li><li>Provides <a href="https://en.wikipedia.org/wiki/Dependency_injection">Dependency Injection</a></li><li>Encourages modular organization</li><li>Provides a command-line interface tool to help initialize, develop, and maintain your application</li><li>Provides support for the most popular extensions like Express.js, Fastify, TypeORM, Passport.js, Apollo GraphQL, Redis, etc.</li><li>Excellent <a href="https://docs.nestjs.com/">free documentation</a> and paid <a href="https://courses.nestjs.com/">video courses</a></li><li><a href="https://enterprise.nestjs.com/">Enterprise support</a> available</li></ul><h3>Drawbacks</h3><ul><li>Uses a <a href="https://www.geeksforgeeks.org/why-node-js-is-a-single-threaded-language/">Single Threaded Event Loop Model architecture</a></li><li>Less performant when servicing requests that take too long or process CPU-intensive tasks</li></ul><p>Out of these concerns, performance may be the most important. Let’s take a look at how NestJS performs.</p><h3>How does it perform?</h3><p>To answer this question, we’ll look at how NestJS handles the total number of requests per second and the average response latency for 64, 256, and 512 concurrent requests. The <a href="https://web-frameworks-benchmark.netlify.app/compare">Web Frameworks Benchmark comparison tool</a> provides a click-and-point solution to visualize performance between different frameworks when running equivalent applications.</p><p>Let’s compare the performance of NestJS configured with the default Express web framework, Java Spring Boot, and C# ASP.NET Minimal API.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*NvZC24qfAz_9buhy.png" /><figcaption><em>Comparison of </em><a href="https://web-frameworks-benchmark.netlify.app/compare?f=nestjs-express,spring,aspnet-minimal-api#totalRequestsPerS"><em>Total Requests per Second for NestJS (Express), Java Spring Boot, and C# ASP.NET Minimal API</em></a><em> from the Web Frameworks Benchmark on March 7, 2022 — higher is better.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2ihKFFOlXx4zl0rB.png" /><figcaption><em>Comparison of </em><a href="https://web-frameworks-benchmark.netlify.app/compare?f=nestjs-express,spring,aspnet-minimal-api#averageLatency"><em>Average Latency for NestJS (Express), Java Spring Boot, and C# ASP.NET Minimal API</em></a><em> from the Web Frameworks Benchmark on March 7, 2022 — lower is better.</em></figcaption></figure><p>The charts above show that NestJS with Express cannot compete with Java Spring Boot and C# ASP.NET Minimal API when using an out-of-the-box configuration.</p><p>To address performance, <a href="https://docs.nestjs.com/techniques/performance">NestJS recommends</a> switching from the default Express web framework to Fastify. This switch is straightforward and should have minimal impact on your code. The charts below show the Total Requests per Second and the Average Latency after switching to NestJS with Fastify.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cO8eB7orYoWorj3k.png" /><figcaption><em>Comparison of </em><a href="https://web-frameworks-benchmark.netlify.app/compare?f=nestjs-fastify,spring,aspnet-minimal-api#totalRequestsPerS"><em>Total Requests per Second for NestJS (Fastify), Java Spring Boot, and C# ASP.NET Minimal API</em></a><em> from the Web Frameworks Benchmark on March 7, 2022 — higher is better.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TtsmzHvyykW27oXH.png" /><figcaption><em>Comparison of </em><a href="https://web-frameworks-benchmark.netlify.app/compare?f=nestjs-fastify,spring,aspnet-minimal-api#averageLatency"><em>Average Latency for NestJS (Fastify), Java Spring Boot, and C# ASP.NET Minimal API</em></a><em> from the Web Frameworks Benchmark on March 7, 2022 — lower is better.</em></figcaption></figure><p>Wow. That’s a huge difference.</p><p>You could integrate caching or run more instances to increase performance further. Those approaches require additional effort or expense.</p><p>Regardless, you’ll never see NestJS perform better in every scenario.</p><h3>Example REST Microservice</h3><p>To demonstrate a basic NestJS application, I’ve provided an example using TypeORM and Swagger that implements a simple Express REST microservice. You can find the application source code on my <a href="https://github.com/christophersmith/nestjs-rest-orm-user-microservice/tree/feature/1-overview">GitHub Account</a>.</p><p>This example application provides REST endpoints to retrieve and manage user records from a database. The endpoints allow you to get a list of all users, get one user, create a user, update a user, and delete a user. All client input, like user identifiers or details, is validated.</p><h3>Development Time</h3><p>Time can vary depending on the team’s skillsets and project functionality. In this instance, it took less than 4 hours to put together this REST microservice with a team consisting of only myself.</p><p>Code development took one and a half hours — including database design, application functionality, Swagger configuration, and the database seeding script.</p><p>My effort for writing tests and documentation took two hours. Setting up data structures to mock database calls from scratch consumed most of the time here. Ideally, I’d leverage or share internal code to minimize the effort.</p><h3>Developer Thoughts</h3><p>Overall, the development experience was enjoyable and has been for other larger projects I’ve done. Time generally spent on boilerplate code was minimal since NestJS provided a lot of the glue and suggested patterns for me already. Overall, NestJS saved a lot of time, and I could quickly knock out a working project.</p><p>NestJS’s decision to use TypeScript provides type safety and helps prevent fewer code issues. Since TypeScript builds on top of JavaScript, developers can tap into the many JavaScript libraries. Developers can also maximize code reuse with other JavaScript-based components like frontends written using React or Angular.</p><p>The addition of Dependency Injection and easy integration with popular libraries are excellent features that saved me a ton of time. The modular architecture lends itself well to a high level of code reuse and a lower maintenance cost.</p><p>NestJS would be a good fit for teams responsible for the full stack: simultaneously developing the backend and a React/Angular frontend. Using the same programming language on both sides expands who can do the work and reduces the bottleneck of needing specialized programming skills.</p><p>One of the few situations where NestJS left me wanting was during testing. The absence of an in-memory SQL Server compliant database for unit testing made me sad, and I spent a lot of time building mocks for the database calls. While there are advocates for not including database calls in unit tests, I prefer to include them.</p><h3>Conclusion</h3><p>NestJS is a solid Node.js framework that allows organizations to leverage their existing JavaScript and TypeScript expertise to develop web-based applications. The opinionated nature enables greater code reuse, especially when paired with React and Angular. NestJS also promotes a loosely coupled architecture with modules and Dependency Injection.</p><p>The “Single Threaded Event Loop Model” architecture of Node.js can hinder NestJS application performance. While specific approaches can alleviate performance problems, NestJS may not be the right fit for all high-traffic or CPU-intensive web applications.</p><p>However, my experience is that not all applications need to scale to Amazon-like performance to create business value. Sometimes, the winners are the languages and platforms that can exploit existing expertise or enable organizations to build more things faster. NestJS is an excellent choice for projects where it makes sense. It should be in your arsenal of tools to call on.</p><figure><a href="https://cta-redirect.hubspot.com/cta/redirect/2399711/2c85370d-6a82-4f11-aee4-b5d3a2964e61"><img alt="Teaser graphic with text that states “Turn your visions into real digital solutions.”" src="https://cdn-images-1.medium.com/max/1024/1*v7WvulucBnqVwh-vF6reLQ.jpeg" /></a></figure><h3>About Mission Data</h3><p>We’re designers, engineers, and strategists building innovative digital products that transform the way companies do business. <a href="https://www.missiondata.com/">Learn more</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=433f62fe4f67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mission-data-journal/lab-notes-looking-at-nestjs-for-web-apps-overview-performance-thoughts-433f62fe4f67">Lab Notes: Looking at NestJS for Web Apps — Overview, Performance, Thoughts</a> was originally published in <a href="https://medium.com/mission-data-journal">Mission Data Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kroger Partnership: Helping implement store occupancy monitoring amidst COVID-19]]></title>
            <link>https://medium.com/mission-data-journal/kroger-partnership-helping-implement-store-occupancy-monitoring-amidst-covid-19-ab0adeb6fa3e?source=rss-cf80862eb3db------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab0adeb6fa3e</guid>
            <category><![CDATA[strategy]]></category>
            <category><![CDATA[internet-of-things]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Chris Smith]]></dc:creator>
            <pubDate>Wed, 15 Sep 2021 12:02:26 GMT</pubDate>
            <atom:updated>2022-10-31T16:19:46.568Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*IgX39paBgmqrue6WS7BQPg.png" /></figure><p>When the COVID-19 pandemic began, grocery retail companies started worrying about keeping brick-and-mortar stores open, employees and customers safe, and their communities fed. Many companies initially acted with handheld tally counters or mobile applications to limit store occupancy. This approach wasn’t feasible for a grocery retailer with 2,700+ locations.</p><p><a href="https://www.kroger.com/">Kroger</a> wanted a safer and cost-effective solution to the problem. To achieve this goal, they recruited the help of <a href="https://www.missiondata.com/">Mission Data</a> and a small team of Kroger employees to deliver viable alternatives.</p><h3>Challenge</h3><p>The solution would need to work when connectivity to a central server was unavailable, minimize the need for additional store labor and not require a rollout of new equipment. Additionally, reporting would be required at the store and corporate levels to satisfy health inspection and compliance needs.</p><h3>Solution</h3><p>We leveraged Kroger’s existing QueVision system to count customers entering the store. QueVision was already available in most stores and forecasts checkout wait times and needed checkout lanes. Building on this existing data source and equipment, we developed an in-store web application that calculated a store’s estimated occupancy. This approach allowed each store to operate without connectivity concerns, and the system sent data to Kroger’s corporate servers daily.</p><p>As ordinances vary locally, the solution also measured occupancy against state or municipality occupancy guidelines considering the store’s square footage and average shop time. The information displayed on in-store monitors allowed associates to ensure occupancy was within safety limits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Efps6u_6GNVWtp0h.png" /></figure><p>Reports produced by the solution provided store and corporate management historical analyses to support operating procedure updates and allowed for compliance reporting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jP06pHM9PBRQNogM.png" /></figure><h3>Results</h3><p>We deployed the project across all stores in early April of 2020, culminating in Kroger’s nationwide communication notifying millions of customers. This project helped Kroger keep all stores open safely — with minimal cost and labor impact — and kept local health inspectors happy while addressing occupancy compliance concerns.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BQ9jJC8Cj0WNulFB.png" /></figure><p><em>Visit our </em><a href="https://www.missiondata.com/our-work/our-clients/kroger/"><em>Kroger Client</em></a><em> page to learn more about the solutions we’ve worked on together.</em></p><figure><a href="https://cta-redirect.hubspot.com/cta/redirect/2399711/2c85370d-6a82-4f11-aee4-b5d3a2964e61"><img alt="Teaser graphic with text that states “Transform your business with innovative digital products.”" src="https://cdn-images-1.medium.com/max/1024/1*DIcGoMJBna5RsxVE-qmrEw.jpeg" /></a></figure><h3>About Mission Data</h3><p>We’re designers, engineers, and strategists building innovative digital products that transform the way companies do business. Learn more: <a href="https://www.missiondata.com/">https://www.missiondata.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab0adeb6fa3e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mission-data-journal/kroger-partnership-helping-implement-store-occupancy-monitoring-amidst-covid-19-ab0adeb6fa3e">Kroger Partnership: Helping implement store occupancy monitoring amidst COVID-19</a> was originally published in <a href="https://medium.com/mission-data-journal">Mission Data Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Labs Notes: BLE Single-antenna Distance Detection Accuracy]]></title>
            <link>https://medium.com/mission-data-journal/labs-notes-ble-single-antenna-distance-detection-accuracy-efaf2fb0bdf3?source=rss-cf80862eb3db------2</link>
            <guid isPermaLink="false">https://medium.com/p/efaf2fb0bdf3</guid>
            <category><![CDATA[iot]]></category>
            <category><![CDATA[location-tracking]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[labs]]></category>
            <category><![CDATA[bluetooth]]></category>
            <dc:creator><![CDATA[Chris Smith]]></dc:creator>
            <pubDate>Tue, 06 Jul 2021 20:59:46 GMT</pubDate>
            <atom:updated>2021-07-06T20:59:46.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*hRSmm_4VibFuWx1KX1cJjA.png" /></figure><p>The ability to accurately track customers, equipment, and products in brick-and-mortar locations can give businesses valuable insights in areas like optimal product placement, asset location, and more. But, unfortunately, the value of these insights is often diminished by high deployment costs, inadequate accuracy for the use case, or the data becomes tainted by optional customer participation. This article explores the distance detection accuracy between a low-cost, fixed-asset Bluetooth Low Energy (BLE) beacon and a low-cost BLE receiver.</p><p>Fixed-asset BLE tracking beacons are battery-powered sensors attached to equipment or products that move around. They are typically easily replaceable and inexpensive, and they broadcast a wireless signal at a fixed interval to maximize battery life. One or more stationary BLE receivers hear those broadcasted signals and detect how “loud” they are (their strength). Wireless signal strength is measured as RSSI, the received signal strength indicator, and is an estimated measure of how well the receiver can hear the beacon. Using RSSI, we can calculate an estimated distance between the beacon and receiver.</p><p>One caveat with using BLE is that it is not very accurate, even in the best conditions. The leading cause of inaccuracy is that BLE operates over the same narrow-band path that WI-FI (2.4 GHz frequency) and other neighboring devices communicate on, much like trying to pick out a single voice in a stadium of screaming fans. This congestion can lead to interference and diffraction. The location’s environment can also impact accuracy. For example, walls, shelves, furniture, and carpet can absorb or interfere with radio signals and influence the detected signal strength.</p><p>This article assumes using an example business goal of detecting bascart locations in a theoretical grocery store. Before I suggest equipping bascarts with low-cost BLE beacons, I’d like to understand whether a low-cost BLE solution is suitable for this use case. To do that, I will start by looking at the accuracy of detected distances between one BLE beacon and one BLE receiver.</p><p>Most USA-based grocery stores use <a href="https://www.discountshelving.com/SoftContent/store-type-grocery-store-shelving.aspx#:~:text=Most%20grocery%20stores%20use%C2%A0Gondola%20Wall%20Units%C2%A0that%20are%2072%E2%80%9D%2C%2084%E2%80%9D%20and%2096%E2%80%9D%20high%20with%20standard%20base%20sizes%20of%2018%E2%80%9D%2C%2020%E2%80%9D%2C%2022%E2%80%9D%20and%2024%E2%80%9D%20depths%20for%20maximum%20inventory%20display%20space.">gondola wall units</a> to display products in aisles. Because those gondola wall units come in standard depths of between 18 and 24 inches, I took the minimum depth, doubled it, and assumed a minimum accuracy tolerance of one meter. This tolerance should give us enough wiggle room to precisely detect bascarts in an aisle.</p><h3>Environment and Equipment</h3><p>Since most of us are WFH, I performed the tests in the most extended area available in my apartment. Eight sets of neighbors surround me, each with WI-FI, cellphones, and various BLE devices. So this setup isn’t ideal and does not mirror the one you’d find in a more controlled environment.</p><p>I used the <a href="https://www.nordicsemi.com/Software-and-tools/Prototyping-platforms/Nordic-Thingy-52">Nordic Thingy:52</a>, with the default settings, as a beacon to transmit a signal once every second — this became the beacon. To read the broadcast beacon signals, I used a <a href="https://www.gsmarena.com/google_pixel_4_xl-9895.php">Google Pixel 4 XL</a> phone with the <a href="https://play.google.com/store/apps/details?id=com.bridou_n.beaconscanner&amp;hl=en_US&amp;gl=US">Beacon Scanner</a> app — this became the receiver. I utilized BLE 5.0 support on both devices.</p><h3>Test Process</h3><p>I placed the beacon (Nordic Thingy:52) in a fixed location at waist height. Then, the receiver (Pixel 4 XL) was moved in half-meter increments away from the beacon, starting at 0.5 meters (about 19.7 inches) and ending at 9.5 meters (about 31.2 feet), along the same horizontal plane with a clear line of sight. At each increment location, 20 RSSI readings spaced one second apart were recorded by the receiver device.</p><p>After capturing the actual distance and RSSI readings, I entered those values into a spreadsheet. Then I used the following RSSI distance calculation, obtained from the <a href="https://iotandelectronics.wordpress.com/2016/10/07/how-to-calculate-distance-from-the-rssi-value-of-the-ble-beacon/">IoT and Electronics</a> blog, to calculate each reading distance.</p><pre>Calculated Distance = 10 ^ ((Measured Power - RSSI) / (10 * Environmental Factor))</pre><p>Please note that calculating distances from RSSI readings will typically result in values with a precision of around plus or minus one meter. Furthermore, RSSI values will show a greater degree of variance the further away the radios are from one another.</p><p>I exported the actual and calculated distance values to a comma-separated-value (CSV) file. I then used the Python modules pandas, matplotlib, and seaborn to summarize the data and create a box plot series and Excel to create line charts. You can find the captured data, spreadsheets, and Jupyter notebook in <a href="https://github.com/christophersmith/missiondata-labs/tree/master/ble-single-antenna-distance-detection-accuracy">my Github repository</a>.</p><h3>Test Results</h3><p>The chart below shows a box plot series of the calculated distance quartiles taken at the actual distance in meters. The black diamonds above the individual box plots show outliers. I decided to keep outliers as I would not know which readings were outliers without additional information.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/697/0*5QMmHaQGMSPfEfy7.png" /></figure><p>The early readings started within an acceptable tolerance range — from the “0.5m” to “1.5m” actual distance increments — with the variance slightly expanding at each increased iteration. However, after the “2.0m” increment, the readings became more unpredictable.</p><p>Let’s look at more detailed charts to see how accurate the RSSI readings are.</p><p>Our first detailed chart is the “Min &amp; Max Calculated Distance vs. Actual Distance” line chart. Here, we compare the Actual Distance, Min, and Max column values.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*o-zLo4W8uWisZJPk.png" /></figure><p>As radios moved further apart, we can see that the minimum calculated distance rate increased less rapidly than the actual distance rate. The maximum calculated distance rate became more unpredictable as the distance increased. The variance between the minimum and maximum is wildly erratic and makes it challenging to obtain an approximate distance within the expected tolerance within a 9.5-meter area.</p><p>From this line chart, we can conclude that a single RSSI reading, with the equipment specified and without additional data, does not produce reliable and accurate approximate distances.</p><p>Finally, I thought it would be interesting to use the average of all readings taken at each increment. I hypothesized that using these averages would significantly reduce unpredictable values and increase accuracy. In practice, this process could be accomplished by taking a series of RSSI readings and averaging them based on a fixed time interval or movement. For this analysis, I used the Mean value for each interval I already had to simulate taking a series of RSSI readings and averaging them.</p><p>The “Average Calculated Distance vs. Actual Distance” line chart compares the Actual Distance and Mean column values to see how well our averaged reading approach fairs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gVjmtXEk0_3V9RdA.png" /></figure><p>My hypothesis was correct, and we now see significantly lower unpredictability with this approach. But, unfortunately, our calculated distance is still inaccurate. While we see some great accuracy with the readings at “1.5m” and “2.0m”, it looks like the other readings would make it difficult to determine whether the beacon was located at “2.0m”, “3.0m”, “4.0m”, “5.0m”, “7.0m”, or “8.0m” away, given our allowed tolerance.</p><p>Let’s visualize the absolute differences between the average calculated and actual distances.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K5LfoBqBevNE4I6M.png" /></figure><p>I added labels to make this chart easier to read. Red data points and labels indicate those values were outside of our one-meter tolerance. From this chart, we can see that the differences begin to exceed our tolerance range after the “2.5m” mark. So our data implies that we’d have to place receivers five meters (16.4 feet) apart, assuming placement along the same plane of our bascart beacons.</p><p>Placing receivers that close together may not be a practical and cost-effective approach. For example, the average grocery store size is 38,000 square feet, <a href="https://progressivegrocer.com/small-formats-big-future-retail#:~:text=The%20average%20grocery%20store%20size,even%20smaller%20in%20urban%20markets.">according to Progressive Grocer</a>. A grocery store of that size would require a minimum of 142 receivers (one for every 268.96 square feet) to cover the entire building, assuming we have the same accuracy and placement limitations. The actual number of receivers required would need to be much higher due to the gondola wall units and products on shelves impacting accuracy.</p><h3>Conclusion</h3><p>Even though my approach didn’t result in a slam-dunk, I learned a lot about the limitations of using inexpensive BLE devices and RSSI for location tracking. The use of individual RSSI readings from a single-antenna receiver resulted in highly variable distance calculations. My approach of averaging those readings faired much better than single readings, but accuracy beyond 2.5 meters still wasn’t good enough for my use case.</p><p>Other approaches would be needed to achieve the desired accuracy.</p><p>Specifically for BLE and beacons, a multi-antenna receiver that uses the <a href="https://www.bluetooth.com/blog/new-aoa-aod-bluetooth-capabilities/">angle of arrival (AoA) or departure (AoD)</a> methods may provide the accuracy needed. This approach is more expensive than a single-antenna receiver. Alternately, supplementing the RSSI readings with data from accelerometer and gyroscope sensors could give more accurate distances but would negatively impact the beacon’s battery life.</p><p><em>Did you find this topic interesting and have a project in mind? Let’s talk: </em><a href="https://www.missiondata.com/contact/"><em>https://www.missiondata.com/contact/</em></a><em>.</em></p><h3>About Mission Data:</h3><p>We’re designers, engineers, and strategists building innovative digital products that transform the way companies do business. Learn more: <a href="https://www.missiondata.com/">https://www.missiondata.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=efaf2fb0bdf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mission-data-journal/labs-notes-ble-single-antenna-distance-detection-accuracy-efaf2fb0bdf3">Labs Notes: BLE Single-antenna Distance Detection Accuracy</a> was originally published in <a href="https://medium.com/mission-data-journal">Mission Data Journal</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>