Rewriting a Ruby on Rails App from MongoDB to PostgreSQL
Rewriting a Ruby on Rails App from MongoDB to PostgreSQL: Lessons from a Live Code and Cloud Migration
May 15, 2025・4 min read
SHARE
When our client—a fast-scaling HR and EdTech platform—approached us to rethink their infrastructure, their Ruby on Rails app was already carrying a significant load. What began modestly on Heroku had evolved into a sprawling system hosted on AWS, powering the daily operations of thousands of educators, administrators, and learners across multiple countries. Years of growth, acquisitions, and technical improvisations had left them with a brittle monolith running on MongoDB. Reporting had become a bottleneck. Development was slowing down. And with GDPR growing ever more critical, a move to a European cloud provider became non-negotiable.
This is the story of how Selleo helped steer this transition—rewriting the data layer, migrating from MongoDB to PostgreSQL, and shifting infrastructure from AWS to Elastisys—all without breaking the platform or disrupting users.
MongoDB was a great choice—once. Its flexibility allowed for rapid prototyping and fast feature rollouts. But over time, speed without structure showed its cracks.
As the platform matured, new challenges surfaced:
Reporting and analytics became core to business intelligence,
Data relationships grew increasingly complex,
Regional teams needed consistency and reliability.
PostgreSQL, with its transactional integrity and relational schema, emerged as the natural evolution. But getting there? That would be a challenge of its own.
Planning a Migration Without Disrupting Production
This wasn’t just a database switch—it was open-heart surgery on a live system.
From day one, Selleo’s Ruby on Rails experts embedded with the client’s team. We didn’t just write code—we co-designed the path forward. Together, we mapped out risks, identified edge cases, and drafted a detailed roadmap. We weren’t a silent vendor. We were in the trenches as strategic partners.
Our work unfolded across two parallel and tightly coordinated tracks:
Data layer rewrite: Moving from Mongoid to ActiveRecord,
Data migration orchestration: Supporting the client’s external consultant during the live migration from MongoDB to PostgreSQL,
Infrastructure transition: From AWS to GDPR-compliant Elastisys.
Each milestone was scoped, prioritized, and reviewed collaboratively. Every change went through transparent, async workflows. Feedback loops were tight. Surprises were few.
Rewriting the Data Layer, Model by Model
Legacy code tends to accumulate chaos. Mongoid models with embedded documents. Others with dynamic attributes. None of them fit neatly into SQL. So we slowed things down.
We began by isolating essential entities—users, assignments, clients. For each, we rebuilt clean ActiveRecord counterparts. We rewrote scopes, background jobs, and API interfaces. Crucially, we preserved method signatures to keep the frontend untouched. We paired on tricky parts. Reviewed thoroughly. And anchored the entire process in robust test coverage—running both MongoDB and Postgres validations side by side.
Running Two Databases—And Sleeping Well at Night
Eventually, we had two versions of the app in staging: the legacy MongoDB-based one and the PostgreSQL-based rebuild. We duplicated frontend clients so QA could A/B test and compare data behavior across systems.
We scripted audits. Compared IDs, states, timestamps. We flagged edge cases before they turned into production headaches. Ownership of data integrity was ours — we traced anomalies and surfaced them early. When testing confirmed all blockers were resolved, we coordinated with all teams and stakeholders to greenlight the production launch. We timed the go-live for a quiet weekend coinciding with public holidays in our client’s key regions. That margin made a difference.
From AWS to Elastisys: A Strategic Infrastructure Shift
While the infrastructure migration was led by the client’s external partners, Selleo stayed close. Having previously architected their AWS setup, we advised on DevOps practices, reviewed migration plans, and helped align the new stack with compliance and operational needs.
The move to Elastisys—a GDPR-compliant European provider—wasn’t just a technical pivot. It was strategic. The client gained clearer billing, data sovereignty, and long-term peace of mind. CI/CD pipelines were rewritten. Observability was baked in. The new infrastructure wasn’t just compliant—it was ready to scale.
Go-Live Weekend: A Story of Quiet Success
It was quiet. Too quiet. During the final migration weekend, we ran the production data conversion script. Switched the database connection. Disabled logins except for selected test accounts. Ran manual smoke tests across all critical paths.Once everything checked out, we opened the gates.
By Monday morning, users logged in as usual. Same flows, same features. But under the hood, everything was different.
Lessons We Learned
It’s hard to grasp the full weight of a migration until you’ve been inside one—living every constraint, every decision, every unknown. Some things only become clear once you’ve lived through a migration like this:
Don’t touch the data until your app logic is airtight,
Test staging like it’s production—because it might as well be,
Treat infrastructure migration as its own standalone project,
Write logs like your future self will depend on them (they will),
Great migrations begin with collaboration, not just code.
Planning a Migration of Your Own?
Whether you're replacing MongoDB, replatforming a Rails monolith, or migrating for compliance reasons — you don’t have to go it alone.
At Selleo, we help companies navigate high-stakes migrations without drama. Our Ruby on Rails teams write clean code, own deliverables, and embed deeply in your context. We anticipate. We plan. We keep you out of the dark. From database refactors to cloud transitions—we’ve done it, supported it, and made it stick.
Using Ruby on Rails could be what you need to take your web app to the next level so stay tuned as we find out how to find and hire Ruby on Rails programmers.
From made-to-order Learning Management Systems to interactive content, we help
leading elearning providers build a more efficient and scalable business.
Business / Corporate Training Software
Educational and Academic Software
Self-education Software
Business / Corporate Training Software
Enhance employee knowledge and performance by delivering training in a way that is tailored specifically towards your business goals.
Faster employee onboarding
Increased training coverage
Enhanced training efficiency
Lower training costs
Educational and Academic Software
Enable students to plan and manage learning processes themselves, so nowadays, the teachers’ role is to facilitate and moderate self-education.
High student involvement
Reduced dropout rates
Maximum learning accessibility
Consistent and relevant content
Self-education Software
Bolster the learning journey, enabling individuals to lock in their focus, boost efficiency, and simplify the learning process at their own pace.