Back
Docker / Backend / FastAPI / DevOps2026

Docker Email Tracker

PythonFastAPIuvicornHTMLPostgreSQLRedis
Docker Email Tracker

Overview

An independent pixel tracking system for monitoring email engagement. It captures "email open" metrics by serving a 1x1 transparent image that triggers a backend event when loaded by a client. The infrastructure uses Docker Compose to orchestrate three services: FastAPI for logic, Redis for high-performance counting, and PostgreSQL for persistent logging. Key features include isolated networks for security, persistent volumes for data integrity, and custom healthchecks to manage service startup order.

Implementation

// production excerpt
app/main.py
# 1x1 pixel beacon. Atomic counting, isolated network, no PII in the URL.
from fastapi import FastAPI, Response, Request
import redis.asyncio as redis

app = FastAPI()
r = redis.from_url("redis://redis:6379", decode_responses=True)  # internal net only

PIXEL = bytes.fromhex("47494638396101000100800000000000ffffff21f9040100"
                      "0000002c00000000010001000002024401003b")

@app.get("/o/{token}.gif")
async def open_pixel(token: str, request: Request) -> Response:
    async with r.pipeline(transaction=True) as pipe:      # atomic multi-op
        await (pipe.hincrby(f"evt:{token}", "opens", 1)
                   .hset(f"evt:{token}", "last_ip_hash", _hash(request.client.host))
                   .execute())
    await audit.log(token=token, event="open")            # durable in Postgres
    return Response(
        content=PIXEL, media_type="image/gif",
        headers={
            "Cache-Control": "no-store",
            "X-Content-Type-Options": "nosniff",
            "Content-Security-Policy": "default-src 'none'",
        },
    )

Atomic Redis counting, hashed client IP, hardened response headers, no PII in the URL.