cd /news/developer-tools/from-react-to-mongodb-how-i-learned-… · home topics developer-tools article
[ARTICLE · art-37809] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

From React to MongoDB: How I Learned Backend Design (The Hard Way) — A Frontend Engineer's Journey

A frontend engineer transitioning to backend development documents the challenges of learning MongoDB schema design and pagination while building a social media app. The developer learned to prioritize access patterns over data relationships and discovered that MongoDB's skip() method reads and discards documents, causing performance degradation on deep pages.

read5 min views6 publishedJun 24, 2026

Two weeks ago, I was a React developer who thought backend was just "API that returns data."

I started building a social media project and hit two problems that made me realize how little I actually knew.

This is me documenting that journey — what confused me, what I got wrong, and what finally clicked. If you're transitioning from frontend too, you'll probably face the same "wait, what?" moments.

Even coming from a frontend background, I knew some backend basics. Enough to feel confident. Enough to think "I got this."

Then I decided to dig a rabbit hole.

I started learning about data modeling and schema design. Came across terms like embedding, referencing, schema design patterns. Read about them. Understood them individually. But something still felt off, like I was missing the actual instinct of when to use which. So I decided to put my hands on a project. Learning by doing.

So there I was, building a social media app. I had three things: Users, Posts, Comments. Simple, right?

Nope.

First real decision: should I embed posts inside the user document or create separate collections and reference them?

I had genuinely no idea. Both sounded fine to me. I almost embedded everything. posts inside users, comments inside posts because that felt "organized." Like keeping things together in one place.

A senior dev would have facepalmed so hard.

Here's what was actually confusing me: I was thinking about how data looks, not how the app uses it. That's where access patterns come into play.

My frontend brain thinks in components. Keep related things together, it makes UI easier. That instinct betrayed me in MongoDB.

The real question isn't "are posts related to users?" , of course they are! The real question is:

Posts grow over time, a user could have 5 posts or 500. Embedding them inside the user document means that document gets bigger every time someone posts. As the document grows, you risk hitting MongoDB's 16MB document limit and creating performance problems long before you get there.

So I referenced them instead:

// User Schema — stores only reference IDs
const userSchema = new mongoose.Schema({
  username: String,
  email:    String,
  posts:    [{ type: mongoose.Schema.Types.ObjectId, ref: "Post" }]
})

// Post Schema — stores who created it
const postSchema = new mongoose.Schema({
  user:    { type: mongoose.Schema.Types.ObjectId, ref: "User" },
  content: String,
  likes:   [{ type: mongoose.Schema.Types.ObjectId, ref: "User" }]
})

Then used populate()

to fetch actual post data when needed.

Access patterns matter more than how data "naturally belongs together." Don't think like a UI developer. Think about how the data grows and how the app reads it with scalability in mind from the start.

Days later, I hit pagination.

I thought skip/limit was just "skip some, take some. Easy."

Nope again.

I built it and it worked. Page 1? perfect. Page 2? fine. Page 50? Suddenly the server was sweating.

Here's what I didn't understand: skip() doesn't actually skip documents. It reads them and throws them away.

So on page 50 with 10 posts per page: MongoDB reads 490 documents → throws them away → returns next 10

Every page deeper you go, more wasted reads. Performance gets worse linearly. On small datasets you never notice. On real data with thousands of posts, it's a problem!

I also got the formula wrong the first time:

const page = req.query.page || 0
.skip(page * postsPerPage)  // starts from page 0 — weird

// What actually makes sense
const page = parseInt(req.query.page) || 1
const skip = (page - 1) * postsPerPage
// page 1 → skip 0  → posts 1-10
// page 2 → skip 10 → posts 11-20
// page 3 → skip 20 → posts 21-30

Page starting at 0 works technically, but page 0 makes no sense to a user. Page 1 is natural. Small thing, real difference.

The correct implementation:

const page         = parseInt(req.query.page) || 1
const postsPerPage = 10
const skip         = (page - 1) * postsPerPage

const posts = await postModel
  .find({ user: user._id })
  .sort({ createdAt: -1 })  
  .skip(skip)
  .limit(postsPerPage)
  .lean()                   

const totalPosts = await postModel.countDocuments({ user: user._id })
const totalPages = Math.ceil(totalPosts / postsPerPage)

When does it matter? If your dataset is small, under a few thousand documents skip/limit is honestly fine. It becomes a real problem at scale, thousands of pages deep, millions of documents. That's also why many large applications eventually move to cursor-based pagination, which avoids the growing cost of deep skips entirely.

But understanding why it gets slow is what separates someone who just makes it work from someone who understands what they built.

These two problems taught me something I didn't expect.

Backend isn't just "make the code work." It's "make it work fast, make it secure, make it scalable."

Frontend taught me to think about UI, about the user's perspective, that 30-second first impression rule, what they see before they even read a word.

Backend is teaching me to think about data, not how it looks on screen, but how it lives in a database, how it grows over time, how the application actually uses it at scale.

Different brains. Same craft.

The confusion is normal.

The problems are common.

And the learning is real.

I'm documenting this journey as I go, not because I'm an expert, but because these are the things that genuinely tripped me up while building projects.

If sharing this saves someone a few hours of debugging, that's a win.

If you're making the jump from frontend to backend too, I'd love to hear what concepts challenged you the most. What was your first "wait, what?" moment?

── more in #developer-tools 4 stories · sorted by recency
── more on @mongodb 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/from-react-to-mongod…] indexed:0 read:5min 2026-06-24 ·