What are server error status codes?

Free preview 4 min to read

The server made a mistake

Imagine you walk into a restaurant and place your order perfectly: correct item, correct table, valid payment. But then the kitchen catches fire. That's not your fault as a customer; the restaurant can't fulfill your request right now.

That's what 5xx status codes represent in HTTP. The client did everything right, but the server encountered a problem and couldn't complete the request.


What makes 5xx different from 4xx?

With 4xx errors, the client is at fault: a bad URL, missing authentication, invalid data. With 5xx errors, the server is at fault: it crashed, timed out, or hit an unexpected condition.

Client Request (valid) ──→ Server (broken) ──→ 5xx Response

"I did my part correctly,     "Something went wrong
 but something broke            on our end."
 on the server side."

This distinction matters because:

  • 4xx: The client should fix the request and retry
  • 5xx: The server team needs to investigate and fix the issue

The 5xx family

Here are the most important server error codes you'll encounter:

Code Name When It Happens
500 Internal Server Error Unhandled exception or crash
501 Not Implemented Server doesn't support the functionality
502 Bad Gateway Upstream server sent an invalid response
503 Service Unavailable Server is overloaded or in maintenance
504 Gateway Timeout Upstream server didn't respond in time
505 HTTP Version Not Supported Server doesn't support the HTTP version used

In practice, you'll deal with 500, 502, 503, and 504 most frequently.


Why 5xx errors are critical

Unlike 4xx errors that affect individual users making bad requests, 5xx errors often affect all users at once:

500 Internal Server Error 503 Service Unavailable
What it means Your application code crashed The server is alive but cannot handle requests
Blast radius Every request hitting the broken code path All users, or only new connections
Usual cause A bug, not configuration Planned maintenance or overload
What to do Immediate developer attention Often self-resolving, or needs scaling

5xx errors are high priority incidents because they mean your application is failing to serve users who are doing nothing wrong.


The role of infrastructure

Modern web applications have multiple layers between the user and your code:

User ──→ CDN ──→ Reverse proxy ──→ App server ──→ Your app ──→ Database
                  (Nginx)          (Puma)          (Rails)      (PostgreSQL)

A 5xx error can originate at any layer:

Layer Typical 5xx
Load Balancer / Reverse Proxy 502, 504
Application Server (Puma) 500, 503
Application Code (Rails) 500
Database 500, 503
External API calls 502, 504

Knowing which layer caused the error is the first step in debugging.


5xx in development vs production

Rails handles 5xx errors very differently depending on the environment:

Aspect Development Production
Error page Detailed stack trace Generic "Something went wrong"
Error details Full exception + source code Hidden from users
Logging Console output Log files + error tracking
Goal Help you debug quickly Protect users and security

In development, seeing a 500 error gives you the full stack trace right in the browser. In production, you never expose internal details: instead, you log them and show a friendly error page.


Summary

Concept Key Point
5xx meaning The server failed to fulfill a valid request
5xx vs 4xx 5xx = server's fault, 4xx = client's fault
Common codes 500, 502, 503, 504 are the most frequent
Impact Often affects every user at once
Infrastructure Errors can come from any layer (proxy, app, database)
Environments Development shows details; production hides them
Lesson 1 of 7 · free

Keep going with lesson 2

500 Internal Server Error

Covers causes of 500 errors in Rails, how Rails handles them, and how to return more specific codes.

A free account also gives you the quizzes, your progress and notes, and the discussion.

Type to start searching...