Skip to main content

SQLAlchemy joinedload vs. join()

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

In SQLAlchemy, both the relationship loading option (.options(joinedload(...))) and the query builder method (.join(TableClass)) result in a SQL JOIN clause. However, they serve fundamentally different purposes and lead to distinct results in the ORM (Object Relational Mapper) layer.

Understanding this difference is crucial for avoiding the common "N+1 problem" and correctly shaping the data returned by your queries.

SQLAlchemy Relationships Without Database Foreign Keys

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

This pattern is often used for:

  1. Legacy Databases: Working with existing schemas that lack proper constraints.
  2. Performance: Avoiding the overhead of transactional foreign key checks.
  3. Data Warehousing: Dealing with schemas where relationships are semantic, not structural.

The key to achieving this is the relationship() function combined with the primaryjoin argument. This allows SQLAlchemy to define the join condition required for the relationship, enabling essential features like eager loading (joinedload, selectinload).

FastAPI Authentication Middleware Example

6 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Authentication Middleware is a crucial component for securing an API by inspecting incoming requests for credentials (like a JWT or API Key) and validating them before the request reaches the route handler. This ensures every protected endpoint is secured automatically and cleanly.

This example demonstrates how to implement a custom authentication middleware to check for a required Authorization header and either inject a valid user/context or reject the request early.

FastAPI Core Middleware Examples and Use Cases

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Middleware in FastAPI (which is built on Starlette) is a powerful mechanism for executing code before and after a request is processed by the route handler. Middleware allows you to apply logic globally or across a group of routes, such as logging, authentication, CORS, and response manipulation.

The standard way to implement custom middleware is by defining an async function that takes the request and the call_next callable.

FastAPI Dependency Injection: Internal Requests, Request Object, and Parameterized Depends

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

FastAPI's Dependency Injection (DI) system is one of its most powerful architectural features. It allows developers to encapsulate authentication, parameter validation, database sessions, and low-level HTTP inspection into reusable, composable units.

This guide provides a comprehensive manual on advanced FastAPI dependency injection patterns: executing in-process internal route requests with TestClient, parameterizing dependencies with factories, accessing the Starlette Request object, nesting dependency resolution chains, and leveraging class-based dependencies.

FastAPI Dependency Injection: The Complete Guide from Basics to Advanced Patterns

9 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Dependency Injection (DI) is one of the core architectural design choices that makes FastAPI so powerful. It handles cross-cutting concerns-such as database connections, security, authentication, and request parsing-with minimal boilerplate.

Whether you are a beginner looking to understand the Depends syntax or an expert building complex authorization layers and mockable tests, this guide covers everything you need to master FastAPI's dependency injection system.

Python Enums: Complete Developer Guide from Basics to Metaprogramming

8 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

In Python, the enum.Enum class is far more than a simple container for constants. It provides a robust, type-safe framework for data validation, serialization, metaprogramming, and static type checking.

Using Enums eliminates fragility across your codebase by replacing raw magic numbers and string literals with structured, immutable objects. By utilizing custom properties and dunder methods (__init__, __new__, _missing_, __str__, __format__), you can embed rich domain logic directly into your constant definitions.

This guide provides a comprehensive manual on Python Enums, covering core foundations, automatic values (auto()), uniqueness validation (@unique), primitive conversions, iteration, type hinting, JSON serialization, and advanced metaprogramming.

Fixing PIL/Pillow IOError: decoder zip not available

4 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

The error IOError: decoder zip not available (or zip decoder not available) is a common hurdle when working with image processing in Python, particularly when handling PNG or TIFF files using the Pillow library.

This error indicates that the underlying C library responsible for image compression (Zlib) was missing or not detected when Pillow was compiled on your system.

GCP IAM vs. AWS IAM: A Deep Dive into Architectural Differences

7 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

While both Google Cloud Platform (GCP) and Amazon Web Services (AWS) Identity and Access Management (IAM) systems share the same goal-controlling who can do what on which resources-they are built on fundamentally different architectural philosophies.

Understanding these differences is crucial for multi-cloud engineers, as applying AWS logic to GCP (or vice versa) often leads to security gaps or unmanageable complexity.

Enable "Last Updated" Docusaurus Dates on Vercel

5 min read
Serhii Hrekov
Senior Software Engineer & System Architect specializing in Python, Web Systems, Cloud Infrastructure & Automation

Docusaurus provides a powerful feature that displays the last updated time and last updated author for every blog post and documentation page. However, when deploying a Docusaurus website on Vercel, many developers encounter the same confusing issue:

Every page shows the exact same "last updated" date - or no date at all.

This guide explains precisely why this happens and the exact configuration you must enable on Vercel to make Docusaurus timestamps work correctly.

Looking for more content?
Hrekov Blog contains 165 articles. Browse the blog archive or Explore the full timeline.