Data linkage and cost optimization achieved with MongoDB Atlas Triggers
This is Kobayashi (@berlinbytes) from the Service Reliability Group (SRG) of the Media Headquarters.
#SRG(Service Reliability Group) is a group that mainly provides cross-sectional support for the infrastructure of our media services, improving existing services, launching new ones, and contributing to OSS.
This article explains the mechanism and examples of MongoDB Atlas Triggers, and introduces ways to improve development efficiency and reduce costs through serverless data linkage and operational automation.
About MongoDB Atlas
MongoDB Atlas is a fully managed cloud database service (DBaaS) available on major cloud providers such as AWS, Google Cloud, and Azure.
It's extremely convenient because it allows you to create a scalable MongoDB environment with just a few clicks while minimizing infrastructure management.
MongoDB Atlas has a feature called "Triggers" that streamlines application development and operations.
By utilizing Triggers, you can perform real-time processing triggered by database changes, as well as regular maintenance tasks, all in a serverless manner.
From here, I would like to introduce the results of my research into how Triggers is being used, based on official examples.
What are MongoDB Atlas Triggers and how do they work?
Triggers is a feature that automatically executes pre-defined server-side logic (Atlas Functions) when specific events occur.
You can implement event-driven processing or periodic tasks without having to provision or manage infrastructure.
There are two main types of Triggers:
1. Database Triggers
This trigger fires when it detects changes to a MongoDB collection (document insertion, update, deletion, or replacement).
Technically, it is based on MongoDB's "Change Streams" feature, and captures change events in real time by monitoring the operation log (Oplog) within the database.
This enables you to build applications that respond immediately to user actions and changes in device state.
2. Scheduled Triggers
This trigger executes a function periodically based on a specified schedule.
You can define the execution frequency using the "CRON" expression, which is widely used in Unix-like systems.
This is suitable for automating tasks that occur over time, such as nightly batch processing, regular report generation, data cleanup, or token renewal for external APIs.
How to use the two triggers
These two triggers can be used depending on the purpose you want to achieve.
- Database Triggers are a good fit Use Database Triggers when you want to respond to "instant changes" caused by users or IoT devices. For example, notifying an ordering system the moment inventory gets low, sending a welcome email upon user registration, or sending a push notification when a chat message is posted. Choose this option if you need to respond immediately to changes.
- Scheduled Triggers are suitable for: They're ideal for operational tasks that are performed in bulk at set times, as well as for cost management. For example, you might want to reduce costs by lowering database specifications outside of business hours, aggregate data every morning to update a dashboard, or periodically delete old log data. You'll probably want to choose Scheduled Triggers for any processing that requires a specific time as the starting point.
Real-time integration with Database Triggers
Here, we will introduce examples of inter-system collaboration triggered by data changes and real-time processing, by pattern.
Instant integration with external systems and event-driven
When data changes occur on MongoDB Atlas, external FaaS (Function as a Service) services such as Azure Functions and AWS Lambda are invoked to synchronize data with other systems.
- Integration with Microsoft Fabric In building a real-time analytics platform, changes to data on Atlas are triggered by Azure Functions, which immediately writes the data to a data lake such as OneLake. This ensures that the analytics platform always has access to the latest data.
- Synchronization to Azure Synapse Analytics Similarly, Atlas is used for real-time synchronization of data from Azure Synapse. By detecting change events and persisting the data, analysis using SQL or Spark becomes immediately possible.
- Catylex (Contract AI) The results of contract document analysis are reflected in each function on an event-driven basis. By automating processes such as data processing, tagging, and integration with external services based on database updates, we have created an event-driven, scalable system.
IoT and Real-Time Control
Database Triggers also seem to be useful for managing the state of physical devices.
- Bosch (Smart Building) This technology was used in a prototype for controlling lighting equipment from an AR app. When a document representing the "light status" in MongoDB is updated, a trigger is fired, and the actual light is turned on/off via the API. The database acts as an intermediary between the app and the physical device, synchronizing the state.
- Arcstone (Manufacturing DX) Event data captured from the production line via Kafka or MQTT is aggregated in Atlas, which then triggers notifications and alerts to be pushed to applications on the manufacturing floor. This functionality can be achieved without setting up your own application server to capture change data.
Improved user experience (notifications and synchronization)
It also contributes to improving the user experience in mobile apps and other applications.
- Official MongoDB Tutorial (Push Notifications) This example demonstrates how a book app can send push notifications to users via the Firebase Admin SDK when new books are added or deleted. By directly linking data updates to notifications, users can ensure they never miss a single update.
- Cognigy (Contact Center AI) Changes in order status caused by chat or voice commands are detected and synchronized in real time with inventory management and delivery APIs. This ensures that the customer service AI always provides accurate delivery status information.
Automate operations and reduce costs with Scheduled Triggers
Next, we will introduce some examples of how Scheduled Triggers, which are executed periodically, have been used to improve operational efficiency and reduce costs.
Cost optimization (auto-scaling/stopping)
Throttling resources during periods of inactivity is a very effective way to manage cloud database costs.
- Clear (Fintech) A major Indian fintech company used Scheduled Triggers to automate the process of scaling down clusters (reducing specifications) at night and scaling them back up (returning specifications) in the morning before business starts. This has resulted in monthly cost savings of approximately $7,000 for 10 clusters.
- TAG (Financial Infrastructure) We optimize costs by dynamically scaling infrastructure up and down based on traffic forecasts. Scheduled triggers enable planned resource adjustments without human intervention, even late at night.
- Atlas Cluster Automation This official open-source tool from MongoDB provides a mechanism for simultaneously pausing and resuming tagged clusters. By automatically pausing clusters that do not need to be running at night or on holidays, such as in development or testing environments, you can prevent unnecessary charges.
Regular maintenance and counting
Regular tasks necessary for stable system operation and data utilization are also automated.
- Autodesk Platform Services We regularly schedule a process to refresh OAuth refresh tokens before they expire. This prevents service outages due to authorization errors.
- Goodnotes (digital note-taking app) We periodically generate "aggregated collections" for use in the search and autocomplete features. By periodically running complex aggregation processes in the background, we can maintain fast response times when users search.
summary
MongoDB Atlas Triggers is a tool that can simplify application architecture and promote operational automation.
"Database Triggers" enable real-time integration and notifications triggered by data changes, allowing you to build event-driven applications.
"Scheduled Triggers" allows you to reduce costs by automatically adjusting resources and perform regular data maintenance without a server.
By using these functions appropriately, it seems possible to not only reduce development time, but also enjoy business benefits such as optimizing infrastructure costs and improving the user experience.
Our company has also benefited from cost optimization using Scheduled Triggers in multiple projects.
If you haven't yet taken advantage of it, why not start by setting up an automatic shutdown of your development environment and implementing a simple notification function?
SRG is looking for people to work with us.
If you are interested, please contact us here.
