# Why I'm Migrating Axion from MongoDB to Postgres

Hey guys! 👋🏻

I wanted to share a big backend decision I made for my microforum, Axion. I'm migrating the database from MongoDB to Postgres.

While MongoDB worked fine to get started, I realized I was fighting against how the database was actually designed to work. Here is why I'm making the switch now:

**MongoDB Was Never Built for Deeply Relational Data.** Microforums are relational by nature—posts have comments and reactions, and users have posts. MongoDB operates on the mindset of *"if X is related to Y, keep them together."*

Postgres, on the other hand, was built specifically for relational data. Its JOINs are optimized, whereas doing relational queries in MongoDB feels like a workaround.

**Automatic Cleanup Instead of Manual Work.** Right now, when a post gets deleted in Axion, I've to handle the cleanup manually:

- Start a transaction
- Run a `deleteOne` operation to remove the post
- Run a `deleteMany` operation to remove the comments
- Run another `deleteMany` operation to remove the likes

It's not that the code is messy, it's just completely manual. Every time I add a new post-related feature—like bookmarks—I've to remember to update the deletion logic to clean those up too. *(Note: Since Axion is meant to be small, instant cleanup isn't an issue yet, though for massive scale, this cleanup architecture won't work* 🙃). With Postgres, cascade deletions automate the process and remove related records for me.

**The Cost of Migration Is Low.** Right now, I've no real users, no production data, and Axion isn't even hosted online yet. Everything in my database is just test data I don't care about. That means I can finish this migration in a day or two without risking data corruption.

**Using the Right Tools for Specific Problems.** Even though these issues aren't hurting Axion at its current small scale, making the jump now sets the app up to scale comfortably into mid-size without technical debt. To keep some of the developer experience I liked with MongoDB, I'm going to pair Postgres with Prisma.

Have you ever migrated databases mid-project? Let's talk in the comments below. See you next time! 🌟
