Tech Terms Explained Open in the app →

ORM

Backend · Beginner · 4 min read

What is it?

An ORM is a tool that lets you work with a database using your programming language's objects instead of writing raw SQL.

Explain like I'm 5

An ORM is like a translator between you and the database: you speak in your code's objects, and it quietly converts that into the database's SQL language.

Why was it created?

Writing SQL by hand everywhere is repetitive and error-prone. ORMs were created to map database rows to code objects and reduce boilerplate.

Where is it used?

  • Backend web frameworks
  • CRUD data access
  • Mapping tables to classes
  • Database-backed applications

Why should developers care?

Most backend frameworks ship with an ORM, so developers use them daily to read and write data.

How does it work?

You define classes that mirror database tables. The ORM translates operations on those objects (create, read, update, delete) into SQL, runs them, and turns rows back into objects.

Real-world example

Instead of writing SQL, you call user.save() or User.find(id); the ORM generates and runs the equivalent SQL behind the scenes.

Common use cases

  • Reducing SQL boilerplate
  • Mapping tables to objects
  • Portable data access
  • Faster development

Advantages

  • Less repetitive SQL
  • Works in your language's style
  • Often database-portable
  • Speeds up common operations

Disadvantages

  • Can generate inefficient queries
  • Hides what SQL runs
  • Hard cases still need raw SQL
  • The N+1 query problem is easy to hit

When should you use it?

For typical application data access where productivity and clarity matter.

When should you avoid it?

For complex, performance-critical queries where hand-tuned SQL is better.

Alternatives

Raw SQLQuery buildersLightweight data-mapper libraries

Related terms

PostgreSQLMySQLSerializationDesign Patterns

Interview questions

Beginner

  • What is an ORM?
  • Why use one instead of SQL?

Intermediate

  • What is the N+1 query problem?
  • When would you drop to raw SQL?

Senior

  • How do you diagnose ORM-generated performance issues?
  • What are the trade-offs of ORM abstraction?

Common misconceptions

  • "An ORM means you never write SQL" — complex queries often still need raw SQL.
  • "ORMs are always slower" — they're fine for most cases; problems usually come from misuse like N+1 queries.

Fun facts

  • ORM stands for Object-Relational Mapping.
  • The N+1 query problem — one query that triggers many more — is the classic ORM pitfall.

Timeline

  • 2000s — ORMs become standard in web frameworks

Learning resources

Quick summary

An ORM maps database rows to code objects so you work in your language instead of raw SQL, cutting boilerplate at the cost of some control.

Cheat sheet

  • Object-Relational Mapping
  • Code objects instead of SQL
  • Reduces boilerplate
  • Watch for N+1 and slow queries

If you remember only one thing

An ORM lets you use the database through your code's objects instead of raw SQL — convenient, but watch the queries it generates.