S.
Home
AboutProjectsBlogLabGalleryContact
HomeProjectsBlogContact

© 2026 Shohjahon Rajabov. All rights reserved.

Back to blog
Engineering
November 20, 2025
1 min read
PythonPostgreSQL

Patterns I use with async SQLAlchemy 2.0

The repository pattern, dependency injection, and a few sharp edges from the async path.

SQLAlchemy 2.0 ships a proper async session via asyncpg, but most tutorials still show 1.x patterns.

The biggest shift is accepting that async sessions are scoped to a single request. I inject an AsyncSession per request and every repository takes it as a constructor argument.

The sharp edge: relationship loading. With async sessions, lazy loading raises MissingGreenlet. I default to selectinload and only revisit when profiling shows a bottleneck.

Share:Share on Telegram
More posts
Infrastructure

What three Telegram bots taught me about state

2 min · April 18, 2026
Engineering

The caching bug that made me stop trusting TTLs

1 min · February 10, 2026