Why does Woovi use MongoDB?
Tags: mongodb, woovi
Published: 2024-07-09 18:15:28

This article explains our decision-making at Woovi to build our fintech on top of MongoDB.

## Why MongoDB?

I think the best two general databases that you can choose to build your Startup are MongoDB or PostgreSQL.

We decided to go with MongoDB for several reasons, outlined below.

## Database migrations

When you are building a new product your data modeling and schema will evolve, and you need to perform database migrations to ensure your codebase only handles one version of these schemas.

When working with SQL you need to perform two types of migrations: structure and data migrations.

Structure migrations are the ones that add, modify, or remove your database schema. Usually using SQL DDL.

Data migration is when you migrate from one data format to another data format. It is like running a _.map_ in some items of some collections. Usually, a script uses database cursors.

When using MongoDB we don't need to care about structure migrations, only with data migrations. No need for up-and-down migrations. You just move forward.

## No need for ORM
Most projects using SQL use an ORM instead of writing pure SQL.
ORM is a bad abstraction that will generate non-optimized queries.
The DX of writing pure SQL is not the best one in most programming languages.

With MongoDB you just use `mongoose` to define your schema and use find, save, and aggregate to perform queries and migrations.

## Database modeling
When you are doing database modeling in MongoDB you focus more on the workload that your product will perform, you focus more on how you are going to read the data than on creating a lot of tables and relationships.

When using MongoDB you can achieve the same data modeling with fewer tables/collections than the counter-party using SQL.
You ended up with a simpler model.

When working on an early stage stage you need to iterate a lot your data model until you finds the one that works, MongoDB makes it easy to iterate.

Another benefit is that you focus on more decoupled modeling with fewer joins/lookups. This helps you at scale if you want to break your system into some microservices.

A decoupled data model creates a decoupled codebase.

## Database scaling

MongoDB is easier to scale than PostgreSQL. It is easier to set up a replica set or sharding than when using PG. 
Database scaling is hard for both.

You can also have a hidden replica to use in your BI system like metabase

## Indexes

MongoDB has many types of indexes to support many use cases.

- single field index: when filtering by a single field)
- compound field index: when filtering by many fields at the same time [https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/](https://emptysqua.re/blog/optimizing-mongodb-compound-indexes/)
- multikey index: array fields
text index: full-text search in many fields in the same collection
- wildcard index: to handle metadata, schemaless design, filter for fields that you don't know yet
- geospatial index: to filter by location, near, intersection, and more
- ttl index

## Unstructured data
NoSQL thrives to store unstructured data that can be processed later on.

## Change Streams

MongoDB Change Streams enable change data capture that makes it possible to sync MongoDB data into other systems, like updating materialized views, updating elastic search data, and enabling realtime updates to WebSockets.


## In Conclusion

MongoDB is a great database for your Startup, and it will handle the scaling when needed.
As your product grows you need to add other specific databases to handle different use cases. Like Redis, Elastic Search, and others.

---
[Woovi](https://www.woovi.com) is an innovative startup revolutionizing the payment landscape. With Woovi, shoppers can enjoy the freedom to pay however they prefer. Our cutting-edge platform provides instant payment solutions, empowering merchants to accept orders and enhance their customer experience seamlessly.

If you're interested in joining our team, we're hiring! Check out our job openings at [Woovi Careers](https://woovi.com/jobs/).

---
Photo by <a href="https://unsplash.com/es/@amayli?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Amélie Mourichon</a> on <a href="https://unsplash.com/s/photos/design-system?orientation=landscape&utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>