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/
- 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 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.
Photo by Amélie Mourichon on Unsplash
Top comments (8)
Good luck migrating once you realize you chose wrong database
Yep. I have been working in enterprise applications and most of the architects regretted using mongodb. Mainly lack of multimaster support and transactions taking too much resources etc. What i have came to realise is if you're making any complex application. You will need both types of databases (OLTP and OLAP) and mostly it's always better to go with Postgres(Cockroach Db if multimaster is required) + Clickhouse . Postgres also has a lot of different flavours available online that makes it easy to switch.
Did u used this DB? Because I'm using it and it gives me a big headache because of corrupting wiredtiger file, so three times I lost all data structure and need to run recovery command 😭😭😭
Use mongo atlas
I know this comment sounds salty and has no explanation. Ill try to explain. 5 years ago I joined a fintech company as junior front end developer. They were using mongo. Still are for about half if the db operations. I didn't know better and have been using mongo for about 5 years since thats what I learned to use. Sadly its terrible choice, especially for finance. Ive been trying to migrate the application for a year and we are likely just 50% there. You really should have very good explanation why relational database does not fit your application before choosing mongo. I personally don't trust any company with my money that starts out with mongo because if the hype that died years ago.
The rule of thumb is to always start with a "traditional" relational database; especially "when working on an early stage stage" and "you need to iterate a lot your data model until you find the one that works", which is never because requirements change all the time :/
Pongo vs exabase?
Sounds like you would like to have Pongo available.