1. where it all starts
i always start by mapping things out in diagrams.net (formerly draw.io). sketch your database schema, your endpoints, how data flows between services. its free and saves as xml or png. takes 10 minutes and saves hours of confusion later
2. python + fastapi
fastapi is my framework. its async, has type hints, pydantic validation, and makes /docs automatically via swagger
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
@app.post("/items/")
def create_item(item: Item):
return {"item": item}
3. postgresql
postgresql for the main database. handles relational data, json with jsonb, and full-text search if you need it. pair with asyncpg for async or sqlalchemy if you want an orm.
# asyncpg example
import asyncpg
conn = await asyncpg.connect(user='user', password='pass', database='db')
rows = await conn.fetch("SELECT * FROM items")
4. redis for caching
redis sits in front of postgres. cache frequent queries, rate limit api calls, store sessions. simple and fast.
import redis.asyncio as redis
r = redis.Redis()
await r.set("key", "value", ex=60) # expires in 60s
value = await r.get("key")
5. elasticsearch for search
only bring elasticsearch when you need real search — millions of documents, fuzzy matching, aggregations. otherwise postgres is enough.
when to use:
product search
log aggregation
analytics dashboards
anything with complex queries on large datasets
6. deployment
railway (easiest)
railway — connect github, it deploys. handles postgres, redis, env vars. free tier works.
docker (more control)
use docker + docker-compose when you need everything containerized:
services:
api:
build: .
ports: ["8000:8000"]
postgres:
image: postgres:15
redis:
image: redis:7
elasticsearch:
image: elasticsearch:8.5.0
7. nginx + cloudflare
nginx in front of your app — handles static files, load balancing, and ssl.
cloudflare tunnel if you want zero open ports and free https. no dns config needed.
cloudflared tunnel create my-api
cloudflared tunnel run my-api --url http://localhost:8000
8. the stack
api: fastapi + python 3.11
database: postgresql 15
cache: redis 7
search: elasticsearch 8 (optional)
reverse proxy: nginx
tunnel: cloudflare tunnel
deploy: railway or docker
9. build :)
start with fastapi + postgresql. add redis when you need caching. add elasticsearch when postgres is too slow.
hope u find this blog useful ! 