Skip to main content
Back to Engineering Lab

Backend Engineering · Containerized REST API · May 12, 2024

FastAPI Blog & Project API Service

A containerized backend API service built with FastAPI, Pydantic v2, PostgreSQL, and Docker Compose for managing blogs, projects, and bcrypt-secured user authentication.

PythonFastAPIPostgreSQLPydantic v2Docker ComposeBcrypt / Passlib

Problem Statement

Content platforms need predictable, schema-validated REST APIs with secure user registration/login, clean relational persistence, and reproducible local development environments across machines.

Architecture & Design Decisions

FastAPI application backed by Pydantic v2 request/response schemas, passlib + bcrypt credential hashing, orjson serialization, and a Docker Compose multi-container stack pairing the Python service with PostgreSQL.

Overview

fastapi-blog is a backend REST API service engineered with FastAPI and PostgreSQL to manage technical blog posts, project records, and user accounts (registration and login). The entire stack is containerized with Docker and Docker Compose for single-command reproducible execution.

Containerized FastAPI Service Topology

HTTP Clients

OpenAPI / JSON Requests

FastAPI Container

Pydantic v2 · Passlib · Orjson

PostgreSQL 13

Persistent Volume Storage

Key Engineering Choices

  • Typed Contracts: Uses pydantic==2.7 and email-validator for strict schema validation on every incoming payload and response model.
  • Security Fundamentals: Passwords are salted and hashed with bcrypt via passlib and cryptography rather than ever stored in plaintext.
  • High-Throughput Serialization: Incorporates orjson and httptools for fast JSON encoding and HTTP parsing.
  • Container-First Workflow: Dockerfile + docker-compose.yml spin up the API service on port 8000 wired to a persistent postgres:13 volume.

Engineering Challenges

  • Designing clean separation between API routers, validation schemas, authentication guards, and PostgreSQL data access.
  • Ensuring reproducible container startup ordering and persistent database volumes via Docker Compose.
  • Enforcing strict input validation and secure password hashing without leaking sensitive fields in serialized responses.

What I Learned

  • Pydantic v2 combined with FastAPI dependency injection creates self-documenting, strongly typed backend contracts with minimal boilerplate.
  • Containerizing both the API and PostgreSQL early eliminates environment drift and makes onboarding effortless.