<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w" -->

---
title: Why I Keep Reaching for SQLAlchemy | daily.dev
description: A developer reflects on why SQLAlchemy earns its place beyond simply avoiding raw SQL: its real value is the unit-of-work pattern for coordinating multi-step...
canonical: https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Why I Keep Reaching for SQLAlchemy | daily.dev
og:description: A developer reflects on why SQLAlchemy earns its place beyond simply avoiding raw SQL: its real value is the unit-of-work pattern for coordinating multi-step...
og:url: https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w
og:image: https://api.daily.dev/og/posts/mQcgfDQ9W.png
og:image:alt: Why I Keep Reaching for SQLAlchemy
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Why I Keep Reaching for SQLAlchemy

**[Atomic Spin](https://daily.dev/sources/atomicobject)** · 2 min read · 0 upvotes · 0 comments

## Summary

A developer reflects on why SQLAlchemy earns its place beyond simply avoiding raw SQL: its real value is the unit-of-work pattern for coordinating multi-step database writes within a single transaction. An example endpoint updating a document status, creating signing sessions, writing outbox messages, and recording an audit event illustrates how these changes must succeed or fail together. The piece also notes SQLAlchemy's downsides—lazy relationships causing hidden N+1 queries, unexpected auto-flushing, and the continued need to understand SQL, joins, and query plans for performance-sensitive work.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://spin.atomicobject.com/keep-reaching-sqlalchemy>

## Questions this post answers

### What is the unit of work pattern in SQLAlchemy and why does it matter?

The unit of work pattern in SQLAlchemy coordinates multiple related database changes, such as updating a document, creating signing sessions, writing outbox messages, and recording an audit event, within a single session and transaction. If any step fails, all changes roll back together, keeping the database consistent even when one request touches several tables and repositories.

_daily.dev surfaces practical takes like this for developers weighing ORM patterns against raw SQL._

### What are the downsides of using SQLAlchemy's ORM in production code?

Lazy relationships can silently trigger dozens of extra queries, and automatic flushing can occur earlier than expected, causing subtle bugs. Mocked sessions in unit tests can hide these behaviors, so integration tests are needed to catch them. Reporting endpoints and performance-sensitive queries are often clearer written as explicit raw SQL instead of ORM expressions.

_developers debugging ORM surprises can find real-world SQLAlchemy gotchas like these on daily.dev._

## Similar posts on daily.dev

- [The revenge of SQL: How a 50-year-old language reinvents itself](https://daily.dev/posts/the-revenge-of-sql-how-a-50-year-old-language-reinvents-itself-ptgmonz65) · InfoWorld · 1 upvotes · 0 comments
- [SQLAlchemy 2 In Practice - Chapter 8: SQLAlchemy and the Web](https://daily.dev/posts/sqlalchemy-2-in-practice---chapter-8-sqlalchemy-and-the-web-czkvocl80) · Miguel Grinberg · 1 upvotes · 0 comments
- [QCon SF: Database-Backed Workflow Orchestration Challenges Traditional Architecture](https://daily.dev/posts/qcon-sf-database-backed-workflow-orchestration-challenges-traditional-architecture-slmsieila) · InfoQ · 1 upvotes · 0 comments
- [Just Use Postgres](https://daily.dev/posts/just-use-postgres-ueffslq3a) · Lobsters · 0 upvotes · 0 comments
- [A stray commit buried multiple levels deep cost me months](https://daily.dev/posts/a-stray-commit-buried-multiple-levels-deep-cost-me-months-auv5pc3lh) · Hacker News · 0 upvotes · 1 comments

---

Tags: [#python](https://daily.dev/tags/python), [#sql](https://daily.dev/tags/sql)

[View this post on daily.dev](https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Why I Keep Reaching for SQLAlchemy","url":"https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w"},"datePublished":"2026-08-19T12:09:02.560Z","dateModified":"2026-09-13T20:34:32.484Z","description":"A developer reflects on why SQLAlchemy earns its place beyond simply avoiding raw SQL: its real value is the unit-of-work pattern for coordinating multi-step...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d1da9de362b9d81bc49288cba9c84f62?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/d1da9de362b9d81bc49288cba9c84f62?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Atomic Spin","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Atomic Spin","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/e2af5ce3adaa403a8cf029268b62419f","url":"https://daily.dev/sources/atomicobject"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,sql","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Atomic Spin","item":"https://daily.dev/sources/atomicobject"},{"@type":"ListItem","position":3,"name":"Why I Keep Reaching for SQLAlchemy"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/why-i-keep-reaching-for-sqlalchemy-mqcgfdq9w#faq","mainEntity":[{"@type":"Question","name":"What is the unit of work pattern in SQLAlchemy and why does it matter?","acceptedAnswer":{"@type":"Answer","text":"The unit of work pattern in SQLAlchemy coordinates multiple related database changes, such as updating a document, creating signing sessions, writing outbox messages, and recording an audit event, within a single session and transaction. If any step fails, all changes roll back together, keeping the database consistent even when one request touches several tables and repositories. daily.dev surfaces practical takes like this for developers weighing ORM patterns against raw SQL."}},{"@type":"Question","name":"What are the downsides of using SQLAlchemy's ORM in production code?","acceptedAnswer":{"@type":"Answer","text":"Lazy relationships can silently trigger dozens of extra queries, and automatic flushing can occur earlier than expected, causing subtle bugs. Mocked sessions in unit tests can hide these behaviors, so integration tests are needed to catch them. Reporting endpoints and performance-sensitive queries are often clearer written as explicit raw SQL instead of ORM expressions. developers debugging ORM surprises can find real-world SQLAlchemy gotchas like these on daily.dev."}}]}
```

