EVENTGet 50% off your ticket to MongoDB.local NYC on May 2. Use code Web50! Learn more >

Building an event-driven inventory management system

Unlock real-time analytics, automation, and workforce efficiency in your inventory operations with MongoDB Atlas.
Start Free
Illustration of an e-commerce mobile app, documents, a pie chart, and magnifying glass.
Solutions overview
Executive summary

In the competitive retail landscape, having the right stock of goods in the right place at the right time is crucial. Too little inventory when and where it’s needed can create unhappy customers. However, a large inventory can increase costs and risks associated with its storage. Companies of all sizes struggle with inventory management. Solutions such as a single view of inventory, real-time analytics, and event-driven architectures can help your businesses overcome these challenges and take your inventory management to the next level. This demo will guide you through the process of building an inventory management system with all the capabilities mentioned above.

Overview

In today’s fast-paced retail landscape, ensuring your inventory is in the right place at the right time is essential. However, the retail industry faces significant challenges in achieving this goal. In 2022, unsold stock in the U.S. surged by a staggering $78 billion, reaching approximately $740 billion — a shocking 12 percent increase.

Without a single view of inventory, retailers struggle to compete with new market disruptors offering customers omnichannel experiences. Retailers who get stock management right can move to distributed supply chains, leveraging stock across online and in-store platforms to distribute inventory quickly and react to shifting buying patterns. With effective access to the data, retailers increase workforce efficiency and allow for automation.

This solution will explore how inventory management affects customer experiences, effective stock management for accurate demand forecasting, and workforce productivity.

Building a single view of inventory to enhance customer experience

Modern retail consumers expect seamless omnichannel experiences, like the ability to view product availability online and pick it up at a nearby store the next day. The difficulty in delivering these features often stems from the lack of a centralized inventory hub, i.e. operating with separate inventories for online and in-store. Combining data from diverse sources becomes a complex task that impacts the retailer's ability to offer customer-centric features.

To track inventory in real time and improve visibility and consistency across multiple channels and locations, MongoDB’s document data model is an ideal choice. Using the document model, data types can be combined easily, making it more flexible for handling diverse product data. Its intuitive design enables developers to iterate on the data model at the same pace as the rest of the code base without downtime for schema changes. This agility accelerates the implementation of new features and functionalities that can be built on top of a single view of inventory, like real-time stock availability, and buying online and picking up in-store the next day. By leveraging a single view of inventory, retailers can accelerate the development of superior customer experiences, securing a competitive edge in the retail industry.

Effective stock management with real-time analytics

When retailers can see and understand inventory levels across their organization in one place, they can begin to manage stock more effectively. This enables retailers to move to a more complex distributed supply chain and activate the use of real-time analytics and AI.

In a traditional retailer without a centralized inventory management system, the complexity of mixing stock between channels is too difficult in a segmented data landscape, leading to waste through dead stock in stores while online channels have insufficient supply of the same item.

With a single view of inventory, items can be moved around in a way that makes sense for the business. Online orders destined for in-store pick-up might be packed using in-store items. Dead stock on a shelf might be available online. Stores can move stock between themselves in an intelligent manner.

The added complexity does come with more complex decision making. It's vital to be able to ask difficult questions of the inventory management system and get answers in real time. Rather than move data to a different analytical platform and get answers a day later, retailers are looking to do real-time analysis to make important stock allocation decisions in real time.

Boost workforce efficiency through an event-driven solution

A successful inventory management strategy also contributes to improving workforce efficiency. The lack of real-time updates results in inefficient inventory tracking procedures and errors, such as excess or unavailable goods, and hinders customer orders, leading to dissatisfaction among staff and customers alike. As the business grows and sales volume increases, the ability to process large amounts of real-time data becomes increasingly important. A future-proof, scalable and flexible architecture supporting the tools that empower your workforce, can make a difference when retailers face a peak in demand or decide to expand their business.

The central question retailers face is, "How can businesses enhance workforce efficiency in their inventory operations?"

The answer lies in using event-driven architectures for managing inventory systems. MongoDB is a great fit for this approach, offering features like Change Streams, Triggers, and the Kafka Connector.

Event-Driven Architecture diagram
Closing the loop for a future-proof inventory management strategy

Effective inventory management strategies are vital in the evolving retail landscape. By providing a consistent single-view inventory, retailers can enhance customer experiences and gain a competitive edge. With efficient stock management capabilities, they can optimize their inventory levels, reducing costs and improving profitability. And by embracing event-driven solutions, retailers can boost workforce efficiency, enabling data-driven decision making and streamlining processes through automation.

While the primary focus is on retail, the solution's benefits extend across industries and use cases. Examples include advanced scenarios such as integrating IoT and RFID tags, delving into AI/ML forecasting for precise demand prediction, and distributed logistics. The versatility of this solution allows its application not only from warehouse to point of sale but also across the entire supply chain, including manufacturing, transportation, and reverse logistics, making it a valuable asset for diverse business domains.

Enhancing Inventory Management with MongoDB video.
A video recording of the demo in action
Reference Architectures
With MongoDB:

Our foundation is a dynamic Next.js application seamlessly integrated with the robust capabilities of MongoDB Atlas.

Within the MongoDB Atlas ecosystem, the MongoDB database comprises three collections: “sales,” “products,” and “orders.” The data retrieval and manipulation of our database is elevated by Atlas Search and Facets. Additionally, the architecture consists of Triggers, enhancing responsiveness and real-time interaction.

Diving deeper, the MongoDB database communicates with our Next.js backend via the MongoDB driver for Node.js, fostering swift and efficient communication. Similarly, the MongoDB database interfaces with the Next.js frontend via App Services, Change Streams, and the Atlas Device SDK.

App Services acts as a smooth pathway that allows information to move seamlessly between the user-facing part of our app (Next.js front end) and the storage part (MongoDB database). This ensures that updates happen on time. Change Streams play the role of an event listener, always paying attention to any changes in the data and quickly sending those changes to the front end so that everything stays up to date in real time. The Atlas Device SDK links the different parts of our app together — the things users see and the behind-the-scenes operations — making sure everything works smoothly, creating a unified and interactive experience for users.

This synthesis ensures a harmonious interaction between the application’s layers, facilitating swift, responsive, and intelligent data management and presentation. Take for example the scenario of a customer purchasing a t-shirt in-store. The point-of-sale device then instantly updates the product stock. If stock runs low, this change is sent immediately through Change Streams to alert the store manager. To further automate the process, MongoDB Triggers can be set up to execute a function that would perform complex actions in response to the event, like automatically reordering products.

Inventory Management system
Inventory Management Platform diagram.
Event-driven workflow overview: Triggers allow automatic replenishment and Change Streams enables real-time low stock alerts
Architecture with MongoDB
Architecture with MongoDB diagram.
Inventory management system architecture using MongoDB Atlas and Next.js
Data model approach

The primary collections — products, orders, and sales — form the foundation of our inventory management system. These collections represent your stock, and incoming and outgoing transactions.

What sets the document data model apart from traditional tabular models is its remarkable flexibility, making it the perfect choice for achieving a single view of inventory. With a tabular approach, achieving a comprehensive overview of your inventory would typically involve complex joins across multiple tables. However, with MongoDB's document model, this complexity is eliminated.

For instance, in the orders collection we take advantage of the Extended Reference pattern when referencing an ordered item. We not only include the product.id, but also the product.name to be displayed in the UI without the need of a join or an extra query to the products collection.

If we now consider the products collection, we see how it encompasses what would have otherwise demanded over 10 tables in a relational system. For example, the product variants are contained as an embedded array in the same document, and other attributes such as product stock or locations would traditionally require additional tables. This transformational power stems from the document model's inherent flexibility. It not only empowers a more intuitive design but also ensures that related data is stored together, optimizing access.

Equivalent relational model for products
Equivalent relational model for products diagram
Product collection equivalent in a tabular setup
Document model
Document model diagram.
Take note of how complex objects and arrays are embedded directly within the document
Building the solution

Building this solution involves six major steps, encompassing MongoDB Atlas setup, your app configuration, and optional personalization steps.

If you want to get hands-on, follow our step-by-step tutorial on how to Build an Inventory Management System using MongoDB Atlas. Access our GitHub repo for code samples, deployment guide, and more!

Key learnings

Throughout this solution, we’ve covered multiple MongoDB topics. Here’s a quick recap of the key learnings:

  • Real-time alerts: Implement real-time low-stock alerts in your front end using Change Streams.
  • Workflow automation: Leverage database triggers to automate stock replenishment workflows.
  • Real-time analytics: Stay on top of your data, analyze trends, and make informed decisions in a timely manner thanks to Atlas Charts.
  • Single view of inventory: Take advantage of the flexibility of the document model to create a comprehensive single view of inventory.

Remember that this is just the beginning. Feel free to explore, tweak, and enhance your inventory management system to fit your own needs.

Technologies and products used
MongoDB developer data platform:
Partner technologies:
  • Next.js
  • React
Author
  • Ramiro Pinto Prieto, MongoDB
  • Tamar Alphaidze, MongoDB
Related resources
general_content_developer

GitHub Repository: inventory-management

Create this demo for yourself by following the instructions and associated models in this solution’s repository.

general_action_read

How to Enhance Inventory Management with Real-Time Data Strategies

Discover how inventory management affects customer experience, effective stock management, and workforce productivity.

general_content_tutorial

Build an Inventory Management System Using MongoDB Atlas

Check out the hands on guide for a simple blueprint of Inventory Management.

general_content_play

Enhancing Inventory Management with MongoDB

MongoDB Industry Solutions discusses how to enhance inventory management with real-time data strategies on top of MongoDB Atlas.

Get started with Atlas today

Get started in seconds. Our free clusters come with 512 MB of storage so you can experiment with sample data and get familiar with our platform.
Try FreeContact sales
Illustration of hands typing on a laptop in the foreground and a superimposed desktop window and coffee cup in the background.