Notes
From the field
Engineering deep dives from production codebases: Android background work, BLE hardware, FastAPI backends and self-hosted infrastructure. No toy examples, just the parts that broke and how they were fixed.
Series
Read in order
Multi-part deep dives, each built from one production codebase.
- 8 parts · 41 minWorkManager in ProductionBackground work that survives process death, flaky networks and big data sets: workers, dependency graphs, progress and failure contracts.
- Injecting Dependencies into WorkManager Workers with Hilt
- WorkerTags — A Central Contract Between WorkManager Scheduler and UI Observer
- Seeding a Room Database with a WorkManager Phased Dependency Graph
- + 5 more
- 5 parts · 31 minAndroid FoundationsThe plumbing every serious app needs: dependency injection, multiple API clients, encrypted storage, printers and test data.
- Three Retrofit Clients in One Android App with Hilt Qualifiers
- Encrypted Token Storage on Android with EncryptedSharedPreferences and Hilt
- Seeding a Room Database via ADB BroadcastReceiver in Kotlin
- + 2 more
- 4 parts · 29 minBLE & AtomBrickOne hardware product end to end: ESP32 firmware, a custom GATT profile, secure pairing and a Kotlin Multiplatform app.
- AtomBrick: ESP32 BLE Motor Controller to KMP Mobile App
- BLE GATT Profile Design for Hardware Control: AtomBrick
- ESP32 BLE Passkey Pairing, Bonding, and Encryption
- + 1 more
- 9 parts · 63 minFastAPI in ProductionA Python backend that holds up: layered architecture, migrations, background jobs, auth, email and object storage.
- FastAPI Layered Architecture — Routes, Services, and Repositories
- Alembic with SQLAlchemy 2.0 Async — Migrations That Hold in Production
- Alembic Async Migrations and Idempotent Database Seeding in FastAPI
- + 6 more
- 4 parts · 37 minSelf-hosted InfrastructureRunning a full dev and production stack on one VPS: Traefik, TLS, firewalls and the docs pipeline.
- Self-Hosted Dev Infrastructure with Docker Compose
- Traefik v3: Routing Multiple Docker Apps on One Server
- Traefik v3: Automatic Routing, TLS, and Middleware for Docker
- + 1 more
Archive
Every note
- Seeding a Room Database via ADB BroadcastReceiver in KotlinManual test data entry wastes development time. This post covers a zero-friction Room database seeder using a BroadcastReceiver, Koin DI, and a single make command.
- AtomBrick: ESP32 BLE Motor Controller to KMP Mobile AppBLE motor control across embedded and mobile is two separate protocol stacks with one shared contract. Build AtomBrick end to end using ESP32, Kable, and Kotlin Multiplatform.
- BLE GATT Profile Design for Hardware Control: AtomBrickGATT profile decisions made early constrain the protocol forever. Build a reviewed profile using UUID selection, characteristic properties, and descriptor design from a real motor controller.
- ESP32 BLE Passkey Pairing, Bonding, and EncryptionThe default ESP32 BLE server accepts any connection. Build a secure peripheral with passkey pairing, MITM protection, and bonding using the Arduino BLE stack.
- Kotlin Multiplatform BLE with Kable, Koin, and ComposeAndroid and iOS BLE share no common API. Build a shared scan-connect-write layer using Kable and KMP targeting both platforms from a single Kotlin codebase.
- Android Project Docs with MkDocs, Dokka, and Firebase HostingMost Android projects ship with no documentation. Build a complete setup, MkDocs Material for the site, Dokka for API reference, Firebase Hosting for deployment, and a GitHub Actions pipeline that ships on every PR.
- WorkerTags — A Central Contract Between WorkManager Scheduler and UI ObserverString literals scattered across worker enqueue calls and UI observers are a silent refactoring hazard. A single WorkerTags object makes the contract explicit, type-safe at call sites, and audit-friendly.
- Passing Structured Failure Data Out of a WorkManager WorkerResult.failure() tells the UI a worker failed. It does not tell the UI what failed. workDataOf() attaches typed output to a failure result so the caller knows exactly which files were not downloaded.
- Bridging WorkManager and Compose UI via a Listener-based ProgressRepositoryWorkManager's built-in setProgress() emits untyped Data blobs. A listener-based ProgressRepository converts worker callbacks into a typed domain model that flows directly into Compose StateFlow without polling.
- Seeding a Room Database with a WorkManager Phased Dependency GraphNaively enqueuing all import workers at once causes foreign-key failures. This post covers a production dependency graph using WorkManager chaining to seed Room in correct order.
- Protecting Downloaded Files with a Rename-to-Backup StrategyAn interrupted download leaves a corrupt or missing file. Renaming the previous version to .bak before the new download starts gives the database seeding worker a fallback — without any network retry.
- Orchestrating Android DownloadManager from a WorkManager CoroutineWorkerWorkManager handles lifecycle and retry logic. DownloadManager handles reliable HTTP transfers. Used together, each does what it is good at. This post covers the coroutine polling loop that bridges them in production.
- Three Retrofit Clients in One Android App with Hilt QualifiersManaging unauthenticated, OAuth 1.0, and Bearer token APIs in a single app requires isolated OkHttpClient instances. This post covers a Hilt qualifier pattern that eliminates injection ambiguity across all three.
- Injecting Dependencies into WorkManager Workers with HiltWorkManager creates workers through its own factory, which means constructor injection fails silently unless you replace that factory with Hilt's. This post covers @HiltWorker, @AssistedInject, and HiltWorkerFactory setup from scratch.
- Encrypted Token Storage on Android with EncryptedSharedPreferences and HiltPlain SharedPreferences stores tokens as cleartext in a world-readable XML file. This post covers a production TokenStore backed by EncryptedSharedPreferences, lazily initialised and injected as a Hilt singleton.
- Printing Labels from Android Using the Brother QL SDKThe Brother printer SDK documentation assumes a Java mindset. This post covers a production Kotlin integration for QL-series label printers over Wi-Fi, including bitmap generation, coroutine bridging, and Mutex-guarded print sessions.
- A Base Worker Template for Batched Room Inserts with Retry and ProgressDuplicating notification logic and batch-insert boilerplate across seven WorkManager workers is how bugs hide. This post covers an abstract base class that reduces each worker to three overrides while handling batching, retries, backup recovery, and progress notifications centrally.
- Traefik v3: Routing Multiple Docker Apps on One ServerPort collisions and manual nginx configs are the price of running multiple Docker apps on one server. Traefik v3 auto-discovers containers and routes each one cleanly using labels.
- Traefik v3: Automatic Routing, TLS, and Middleware for DockerNginx breaks every time a container restarts with a new IP. Traefik watches the Docker socket and rebuilds routes automatically, TLS included. Complete production setup from scratch.
- Self-Hosted Dev Infrastructure with Docker ComposePer-project service duplication wastes time and breaks isolation. Build one shared infra stack with Traefik, PostgreSQL, Redis, MinIO, and Mailpit that every app joins over a named Docker network.
- Docker on a VPS: UFW, Port Bindings, and SSH TunnelsDocker bypasses UFW by default, so a misconfigured port binding exposes your database to the internet regardless of your firewall rules. Here is the binding strategy and SSH tunnel workflow that actually locks things down.
- Stateless OTP Login in FastAPI with JWT and RedisPassword databases are a liability. Build a stateless OTP login flow in FastAPI using signed JWTs as verification tokens and Redis for single-use enforcement.
- MinIO as a Self-Hosted S3 Backend in DockerAWS egress costs and vendor lock-in are avoidable. Run MinIO as a drop-in S3-compatible object store in Docker, wired into your existing infra stack with zero app-code changes.
- Mailpit as a Dev SMTP Catch-All Behind TraefikOutbound emails in dev either silently fail or hit real inboxes. Run Mailpit as an SMTP catch-all in Docker, routed through Traefik with auth, persistence, and a Web UI.
- FastAPI Layered Architecture — Routes, Services, and RepositoriesFlat FastAPI routes that do everything are fast to write and painful to maintain. This post covers the three-layer architecture that keeps query logic, business logic, and HTTP concerns cleanly separated.
- Celery + Redis in Production — Task Reliability with acks_late and Retry BackoffDefault Celery configuration loses tasks silently when workers die. This post covers the four settings that make Celery safe under real failure conditions, with the exact configuration from a production FastAPI backend.
- Monitoring Celery with Flower — Local Setup and SSH Tunnel for Remote ServersFlower exposes your Celery queue to the public internet if configured carelessly. This post covers local development setup and a secure SSH tunnel approach for remote production monitoring.
- Async Email Delivery in FastAPI — Two SMTP Paths, One Jinja2 Template SystemOTP emails and welcome emails have different latency requirements. This post covers a dual-path SMTP design where time-sensitive emails send inline with aiosmtplib and background emails queue through Celery with smtplib.
- Alembic with SQLAlchemy 2.0 Async — Migrations That Hold in ProductionSQLAlchemy async models and Alembic fight each other until you wire them correctly. This post covers the full setup: env.py for async engines, autogenerate that actually catches your changes, and a safe rollback strategy.
- Alembic Async Migrations and Idempotent Database Seeding in FastAPIAlembic's default env.py is synchronous. This post covers the async migration setup, auto-database creation, and an idempotent seed script that is safe to re-run at any point.