Join us Sept 17 at .local NYC! Use code WEB50 to save 50% on tickets. Learn more >
MongoDB Event
Docs Menu
Docs Home
/ /
Atlas Architecture Center
/ / /

Event-Driven Inventory Management System

Unlock real-time analytics, automation, and workforce efficiency in your inventory operations for retail and manufacturing with MongoDB Atlas.

Use cases: Catalog, Analytics

Industries: Retail, Manufacturing

Products: MongoDB Change Streams, MongoDB Atlas Charts, MongoDB Atlas Search, MongoDB Atlas Triggers

Partners: Next.js

In the competitive business landscape of retail and manufacturing, having the right inventory of goods in the right place at the right time is crucial. Insufficient inventory leads to operational disruptions and missed opportunities. Excess inventory increases costs and risks associated with 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 businesses overcome these challenges and improve their inventory management.

This guide covers the process of building an inventory management system tailored for diverse industries, such as retail and manufacturing.

Retailers today need a unified view of their inventory to meet customer expectations for immediate availability and seamless purchasing experiences. The disparity between online and in-store stock can lead to missed sales opportunities and customer dissatisfaction.

An inventory management system can provide the following benefits:

  • Effective Stock Management enables retailers to leverage distributed supply chains, moving inventory fluidly between channels to meet demand where it arises. This reduces the risk of dead stock in physical stores and stock-outs in online channels, enhancing overall inventory efficiency.

  • Real-time Analytics empower retailers to make data-driven decisions, adapting quickly to changing market conditions and consumer behavior. Furthermore, automated processes reduce manual errors and free up staff to focus on value-added activities, such as enhancing service quality.

  • Event-driven Architectures facilitate these improvements, allowing for seamless inventory data integration and synchronization across various platforms and devices.

Real-time wind turbine diagnosis

Figure 1. Inventory management overview

In this system, MongoDB helps businesses enhance service quality, workforce efficiency, and optimize stock management by enabling a single view of inventory, event-driven architectures, and real-time analytics.

These capabilities lay the groundwork for other advanced scenarios, such as:

  • IoT and RFID Tag Integration

  • AI/ML Forecasts for precise demand prediction

  • Distributed logistics

The inventory management solution leverages a Next.js application seamlessly integrated with MongoDB Atlas, providing a flexible and scalable backend, as shown in Figure 2.

The solution uses the following components:

  • MongoDB Atlas Database houses four key collections: products, transactions, users, and locations. These collections manage inventory, process transactions, and track user and location data.

  • ACID-compliant operations ensure data consistency and integrity, particularly during stock level changes due to transactions. Both the products and transactions collections receive updates to maintain reliability and consistency across the system.

  • The application connects to MongoDB through the MongoDB Node.js driver.

  • Atlas Search enhances the applications' search capabilities, enabling advanced full-text search features. This allows users to perform complex queries, such as searching by product category or applying facet filters.

  • Atlas Triggers automate backend logic by executing functions in response to database changes, such as automatically reordering inventory when stock falls below a certain threshold.

  • Change Streams act as real-time listeners, detecting changes in the database and pushing updates to the application. This enables real-time alerts, such as low stock notifications, to be sent to inventory managers.

  • Atlas Charts provides a visualization tool for real-time analytics, allowing users to create interactive charts and dashboards directly from MongoDB data. This empowers decision-makers to track key metrics, such as inventory levels and sales trends, in real time.

  • Workload isolation analytics queries run on a dedicated node, which ensures that operational performance remains unaffected.

This cohesive architecture supports real-time data interactions and automates key tasks to streamline processes. It allows the Next.js application to provide a responsive and dynamic user experience, built on MongoDB's robust data management features.

Through this integration, the solution effectively balances performance, automation, and scalability, making it well-suited for modern inventory management challenges.

Inventory management system with MongoDB.

Figure 2. Inventory management system architecture using MongoDB Atlas and Next.js

The inventory management system stores data across four collections: products, transactions, users, and locations. These collections respectively represent stock, incoming and outgoing movements that affect stock levels, application users, and the locations the system serves.

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

Equivalent relational model for product.

Figure 3. Product collection equivalent in a tabular setup

The transactions collection uses the Extended Reference pattern to reference items. As such, the transaction document includes the product.id field for internal reference, and the product.name. This pattern allows the UI to display relevant information to the user without using additional queries or joins on the products collection.

The products collection contains what would require 10 separate tables in a relational database. The individual documents include:

  • Embedded arrays for product variants, allowing different configurations of the same product to be stored together.

  • Product stock and location information, which would typically require additional tables in a relational database.

This flexibility provides a more intuitive design, optimizes data access, and ensures related data is stored together.

Database Model with MongoDB.

Figure 4. Representation of how complex documents and arrays are embedded within the document

Here's an example of a product document:

{
"type": "inbound",
"location": {
"origin": {
"type": "warehouse"
},
"destination": {
"type": "factory",
"id": {
"$oid": "65c63cb61526ffd3415fadbd"
},
"name": "Bogatell Factory"
}
},
"placement_timestamp": {
"$date": "2024-04-08T15:13:58.822Z"
},
"items": [
{
"sku": "CT001-PT-MDB0001",
"name": "Programmable Thermostats",
"unit": "pieces",
"delivery_time": {
"amount": 3,
"unit": "seconds"
},
"status": [
{
"name": "placed",
"update_timestamp": {
"$date": "2024-04-08T15:13:58.822Z"
}
},
{
"name": "arrived",
"update_timestamp": {
"$date": "2024-04-08T15:14:03.741Z"
}
}
],
"amount": 15,
"product": {
"id": {
"$oid": "65cce1a4ccdfb7402dbb4db4"
},
"name": "Controls and Thermostats",
"image": {
"url": "/images/products/thermostats.png"
}
}
}
],
"automatic": true,
"transaction_number": 133
}

To replicate this solution, you need to setup MongoDB Atlas and to configure your application. For detailed instructions, see the GitHub repository. The GitHub page guides you through the following steps:

1

Create a MongoDB Atlas cluster and replicate the collections, views, and indexes from the demo database.

2

Create a database trigger that automatically issues a replenishment order when stock levels fall below a defined threshold. For demo purposes, set up a second trigger to simulate an order's progress from placement to fulfillment.

3

Configure search indexes for full-text search and filter facets in the products and transactions collections.

4

Enhance your application's visualization and analytics capabilities with Atlas Charts. Unlock real-time analytics and create custom charts based on your preferences.

5

Clone the GitHub repository to your local machine, update the environment variables with your own values, install the dependencies, and run the app locally at http://localhost:3000.

This solution highlights the following capabilities:

  • Real-time alerts: Implement real-time low-stock alerts in your frontend 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 with Atlas Charts.

  • Single view of inventory: Take advantage of the flexibility of the document model to create a comprehensive single view of inventory.

Feel free to explore, tweak, and enhance your inventory management system to fit your own needs.

  • Dr. Humza Akhtar, MongoDB

  • Ramiro Pinto Prieto, MongoDB

  • Tamar Alphaidze, MongoDB

  • Building Modern Omnichannel Ordering on MongoDB

  • AI-Driven Real-Time Pricing with MongoDB and Vertex AI

  • RFID: Real-Time Product Tracking

Back

Text-to-Audio News Conversion

On this page