r/Backend • • 15h ago

Designing HTTP API and domain errors around RFC 9457 (so clients stop parsing English error strings)

0 Upvotes

Most API teams spend weeks designing `200 OK` schemas and 10 minutes improvising `4xx`/`5xx` JSON. You end up with three different error shapes across endpoints, brittle client regexes parsing `message` strings, and occasional raw SQL errors leaking through generic 500 handlers.

Using **RFC 9457 Problem Details** (`application/problem+json`) with strict internal-to-external error mapping solves a surprising number of production headaches at once:

- Clients branch on stable `type` URIs (and structured extension fields like `retryable` or field-level validation errors), never human-readable `detail` prose.

- Retry middleware can distinguish transient infra faults from permanent domain rejections without guessing from status codes alone.

- Security boundaries stay clean because internal stack traces/driver errors map explicitly to sanitized problem types while keeping correlation IDs for server logs.

I wrote an open guide walking through the RFC 9457 structure, domain error mapping patterns, and observability pitfalls (disclosure: my site):

https://olmene.com/article/designing-api-and-domain-errors-around-rfc-9457

For teams already using Problem Details in production: do you host actual docs pages at your `type` URIs, or use `urn:` identifiers?


r/Backend • • 16h ago

Is migrating from MongoDB to PostgreSQL worth it?

28 Upvotes

TL;DR: Running an EdTech platform with 600K+ users on MongoDB. Our data is heavily relational, and while regular API queries perform well, complex analytical queries are becoming painful to write and execute. Considering migrating to PostgreSQL and looking for advice on migration and production hosting.

Current setup:

\\- Node.js, MongoDB, and Mongoose.

\\- MongoDB Atlas (fully managed).

\\- 600K+ registered users and around 15K daily active users.

\\- An EdTech platform somewhat similar to Udemy or Coursera.

When the backend's foundations were laid, I was a junior working primarily on the frontend, so I wasn't involved in the database decision. It's been 1 year since we've been building this product.

Something that has been bothering me for a while is that we're essentially treating MongoDB like a relational database.

\\- Strict schemas and validations across collections.

\\- Heavily relational data with references between collections.

\\- Extensive use of aggregation pipelines and "$lookup".

\\- Very little reliance on MongoDB's schema flexibility.

To be fair, MongoDB has served us well. Our indexes are in place, most endpoints perform well, and we haven't faced any critical performance issues.

However, complex analytical queries for internal dashboards are a different story. Some involve joining up to 10 collections, take over 60 seconds, or occasionally time out despite optimization. Writing and maintaining these aggregation pipelines is also becoming increasingly painful.

I've experimented with MongoDB's transactions but didn't particularly enjoy the experience. I'd also like stronger database level relational integrity and better transaction management.

I feel PostgreSQL would have been a more natural fit for our data model from the beginning.

What I'd like advice on:

  1. Is migration justified? Given that MongoDB works well for most of our workloads, would migrating to PostgreSQL be worth the effort, or should I address the analytical workload separately?
  2. Migration strategy: If I proceed, how should I approach migrating a live production database at this scale? Any articles, case studies, or resources would be appreciated.
  3. PostgreSQL hosting: One thing I genuinely appreciate about MongoDB Atlas is how little I have to worry about infrastructure, backups, updates, and maintenance. What's the equivalent experience for PostgreSQL?
  4. Self-hosted vs. managed: How do you guys run PostgreSQL in production? Do you self-host it on a private EC2 instance or use something like AWS RDS, Neon, or another managed provider?

I've worked with relational databases on smaller projects, but never operated PostgreSQL in production at this scale.

I don't want to migrate just because I prefer PostgreSQL, but I also don't want to ignore what might be a fundamental architectural mismatch simply because things work today.

Would love to your thoughts and suggestions on this!


r/Backend • • 23h ago

Hey I am Backend-developer all i know i have built many projects apply many things and concepts all i want to add payment systems that should be productional and industry accpted and with handling millions of users and by focusing this payment thing which Backend project will be great to know

1 Upvotes

r/Backend • • 16h ago

How do you guys test your backends in production?

6 Upvotes

I'm a junior engineer working in a small team. We've been building a product for around 8 months using Express.js, and shipping features has always been our biggest priority.

One thing I've been noticing lately is that as our codebase grows, shipping a new feature occasionally breaks something that was previously working. Sometimes we don't even realize it until a user reports it.

We have a handful of basic tests, but nothing comprehensive enough to give us confidence when shipping new features or refactoring existing code.

I want to change that.

I've heard about unit testing, integration testing, end-to-end testing, smoke testing, and load testing, but my practical experience beyond basic tests is pretty limited.

I'd love to understand:

- What kinds of tests do you actually write for your backends?

- How do you decide what to test and what not to test?

- How do you introduce testing into an existing codebase without slowing down development significantly?

- What tools and frameworks do you use?

- How do you structure your testing suite and integrate it into CI/CD?

I'd particularly appreciate practical resources, open-source repositories with good testing practices, or engineering articles that demonstrate how these things are done in real projects.

I don't want to write tests just to increase a coverage percentage. I want to reach a point where we can ship features and refactor code without constantly worrying about what we might have broken.

Would love to hear how you guys approach this in your daily work.


r/Backend • • 5h ago

How are you checking email addresses during signup when using AWS SES? Are you relying on format checks or using a separate verification service?

5 Upvotes

I was checking our email logs recently because we've had more messages bouncing than usual. We're using SES to send transactional emails from our web app and at first I thought something had changed with the setup. I went through the DNS records and sending configuration but couldn't find anything obviously wrong then I took another look at our signup process. Right now, we only check if the email follows the correct format. Someone could easily enter an address with a typo or one that doesn't actually exist and still get through.

We're not sending thousands of emails every day so even a handful of bad addresses can make a noticeable difference to our bounce rate. I'm wondering if it's worth adding an email verification API before accepting new accounts. How are you handling this in your own applications? Do you verify addresses before sending anything through SES or is the built-in handling enough to keep things under control?


r/Backend • • 16h ago

How do you run PostgreSQL and Redis in production?

17 Upvotes

Title:

TL;DR: Migrating to PostgreSQL and introducing Redis for a production application with 600K+ users and around 30K DAUs. Looking for advice on hosting, managed services, and operational best practices.

We've been building a product for over a year using Node.js, Express.js, and MongoDB. We've now decided to migrate to PostgreSQL and replace our basic in memory caching with Redis.

One thing I genuinely love about MongoDB Atlas is how little I have to worry about the database itself. Backups, security, updates, scaling, and maintenance are largely taken care of. I just pay for it and focus on building the product.

Now that we're moving to PostgreSQL, I'm looking for a similar experience. I'm also introducing Redis since our current in-memory cache gets wiped with every deployment.

My questions:

- Do you self-host PostgreSQL and Redis or use managed services?

- Which managed providers do you use and recommend?

- If self-hosted, how do you handle security, backups, availability, and maintenance?

- Is the cost saving of self-hosting worth the operational responsibility?

Our backend runs on AWS EC2, so RDS and ElastiCache seems like natural choices but I've not used them till date and want to know all the other options and pick the best one accordingly to our needs and preferences.

I've used PostgreSQL for smaller projects but never operated it in production at this scale.

I'd love to hear what you guys actually use in production, your experience with different providers, and what you'd recommend based on our scale.


r/Backend • • 13h ago

Adding one cache server can send 18× the traffic to your database.

Thumbnail gallery
2 Upvotes