- Use cases: Omnichannel Ordering, Catalog, Event-Driven Inventory
- Industries: Retail
- Products and tools: MongoDB Atlas, Change Streams, Atlas Triggers
While customers today expect seamless shopping experiences that effortlessly blend online and offline channels, retailers struggle to implement modern omnichannel solutions to meet customers where they shop with a consistent experience across all touchpoints.
While offering convenient options like “Buy Online, Pick Up In Store” (BOPIS) and “Buy Online, Get Delivery at Home” is essential for remaining competitive, implementing an omnichannel strategy presents significant technical challenges. Retailers need a flexible system that can provide real-time visibility, handle dynamic traffic patterns, and enable modern integrations across all customer touchpoints.
This solution demonstrates how to build an omnichannel e-commerce website using MongoDB Atlas. The demo showcases a customer journey where users can choose their preferred shipping method (BOPIS or home delivery) and track their order progress in real time until delivery. By leveraging key MongoDB features including Change Streams, Atlas Triggers, and the flexible document model, you'll learn how to create a robust, scalable omnichannel ordering system.
At its core, this solution leverages MongoDB's Change Streams and Atlas Triggers to enable real-time data operations across multiple applications. The architecture consists of two main components: Real-Time Apps and MongoDB Atlas.
The Real-Time Apps side includes any application that responds to the database changes, such as e-commerce, distribution center, warehouse, and inventory apps.
Within MongoDB Atlas, the workflow is as follows:
Beyond our current implementation, this architecture provides a foundation for various real-time scenarios, such as:
The simplicity of this process comes from MongoDB’s replication feature and the underlying operations log (oplog), which records all database changes. This mechanism allows Change Streams to efficiently push updates to your application without adding extra layers or complexity. Replication primarily ensures high availability by maintaining multiple copies of data across nodes and enables real-time updates. Applications can monitor changes at different scopes (collection, database, or cluster-wide) and filter specific changes using the Aggregation Framework.
When a developer writes an algorithm, complexity doesn’t have to mean complication. More lines of code don’t always equate to a better solution. The key is simplicity. Simple solutions are easier to understand and quicker to implement, allowing you to focus on what truly matters: innovation.
Our solution's data model revolves around two primary collections: products and orders. Each collection uses a "field": "value" format, providing an organized representation of the stored data. Let's examine how each collection is structured:
Products collection:
Orders collection:
The value of this model lies in its flexibility. By enabling the data structure to evolve with the user workflow, it allows the business to easily adapt to both current needs and future challenges that may arise. For instance, a product MongoDB document includes a field named “price,” which holds an array of values allowing for representation in multiple currencies, such as 12 USD.
This data model design supports complex business requirements while maintaining simplicity and flexibility in the development process.
Building this solution can be broken down in three major steps:
Step 1: Replicate the demo database. Provision a cluster within your Atlas account and populate your database with the data required for the demo. A data dump can be found inside the repository to quickly replicate the database with all the necessary data and metadata with one quick mongorestore command.
Step 2: Add the order status trigger. Create a database trigger that listens to the orders collection for any insert and update event. This will run a function that you can copy from the github repository. Because the use case of this demo focuses on the experience of the customer ordering from an e-commerce website, this trigger helps us mimic the behind-the-scenes processes needed to update the order status every 10 seconds, progressing the order through each stage until the order is marked as delivered. Some of the backend processes we mimic are workers from the warehouse managing the order, postal services delivering packages, or store employees packing an order.
Step 3: Configure your application’s frontend. Obtain the demo code by cloning the GitHub repository to your local machine, configure the environment variables and install the dependencies. Finally, run the app locally at http://localhost:8080/cart.
For complete implementation details, including code samples, configuration files, and tutorial videos, visit the GitHub repository: https://github.com/mongodb-industry-solutions/retail-store-v2.
This solution demonstrates three core capabilities of MongoDB that make it well-suited for omnichannel retail applications:
Each of these capabilities contributes to building a robust omnichannel ordering system that can scale with your business needs while maintaining performance and reliability.
Discover how MongoDB enhances omnichannel experiences.
Run this demo by following the instructions in this solution’s repository.
Discover how leading industries are transforming with AI and MongoDB Atlas.
Learn how MongoDB shapes the retail industry through innovative solutions.