Follow Pay
From a simple Supabase backend to a distributed system with real-time chat, production AI support, moderation, and self-hosted delivery.
Architecture evolution
- V1Supabase-first
Flutter UI, GetX, and Supabase — intentionally simple to ship the product idea quickly.
- V2FastAPI enters
As we thought about future load, Python/FastAPI took on more backend and API logic.
- Incident~10K traffic spike
Sudden traffic hit; Python servers went down. Approximately 14 hours of stabilization work followed.
- V3Supabase RPC shift
Moved Python-side functions into Supabase PostgreSQL RPC to reduce pressure on the Python servers.
- CostInfrastructure pressure
Several months later (~4–7 months in), Supabase and DigitalOcean bills had climbed too high.
- V4Self-hosted Supabase
Moved Supabase onto our own Docker-based infrastructure for cost and control.
- DeliverySelf-hosted CI/CD
Custom scripts and locally managed server workflows for mobile/backend delivery instead of relying entirely on third-party hosted CI.
- LaterTelegram verification in-app
Needed a Telegram-related verification flow inside Follow Pay. Existing Flutter/Telegram libraries were not reliable enough for the required path, so I investigated handy_tdlib and developed a working patch — used in production for about a year.
- V5Social + chat stack
Go, Dragonfly, WebSockets, REST, and local storage for social/chat responsiveness.
- V6State synchronization
Hardened WebSocket + REST + local-storage cooperation so chat state stayed consistent.
- AISupport + moderation
Production AI support assistant with application-context access, plus AI-assisted content and behavior moderation for social surfaces.
Starting point
Follow Pay started from the product idea. The first implementation was intentionally simple: a Flutter UI with GetX on top of a Supabase backend. At that stage, Supabase was enough to get the product moving quickly.
As the product grew, we started thinking about future load and introduced Python with FastAPI. FastAPI became responsible for handling more backend and API logic while the mobile client continued to evolve.
The ~10K traffic incident
At one point, approximately 10,000 traffic came in suddenly, and the Python servers went down. The architecture had been designed incrementally, but the spike exposed a weakness in how much of the system still depended on the Python layer staying healthy under pressure.
That night, we worked for approximately 14 hours to stabilize the system. The solution was not simply buying a bigger server. We moved Python-side functions into Supabase PostgreSQL RPC functions, reducing the amount of application logic that had to pass through the Python server.
It was an architectural response to a production failure: move critical work closer to the database path that could absorb the load more reliably in that moment.
Infrastructure cost pressure
Several months later — approximately 4–7 months into the project — another problem appeared. The system was working, but infrastructure costs had become too high. The Supabase bill increased. The DigitalOcean infrastructure bill increased.
At this stage I was increasingly working on the backend and infrastructure side and managing my own servers. I started asking whether we really needed managed infrastructure for everything.
Self-hosting Supabase
I decided to move Supabase from the managed environment onto our own infrastructure using Docker. The goal was greater control over infrastructure, deployment, cost, server resources, and backend architecture.
After moving Supabase to our own servers, the infrastructure became much smoother from a cost and control perspective. Exact percentage savings aren't claimed here — the meaningful change was ownership of the trade-offs.
Custom self-hosted CI/CD infrastructure
I designed and implemented custom CI/CD workflows for Follow Pay's mobile and backend systems using purpose-built scripts and a locally hosted, self-managed server rather than relying entirely on third-party hosted CI platforms.
The delivery work was tailored to the application's real architecture: packaging and deploying backend services onto infrastructure I controlled, with native build scripts for the Go services, isolated Python environments for the FastAPI worker path, and systemd-oriented host layouts for long-running processes.
Verified delivery pieces include remote deploy automation that uploads a backend package over SSH, prepares an isolated virtualenv, restarts the application process, and runs basic local health checks; native `go build` scripts for the chat backend and moderation worker; and host documentation for Debian/Alma-style service paths. This is ownership of the execution environment — not a claim of zero-downtime clustering or fully hands-off release automation.
- Custom scripts for backend packaging and host deploy automation
- Self-hosted / locally managed server as the execution environment
- Native Go build scripts for chat and moderation workers
- Isolated Python virtualenv deploy path for the FastAPI worker
- Process restart + basic health-check verification after deploy
- Direct control over build and runtime layout on owned infrastructure
AI-powered support & moderation
Follow Pay runs a custom AI-powered support system in production. It is not just a chatbot UI — it is an application-integrated assistant that can gather relevant user and account information in a primarily read-oriented way and answer support questions with that live context.
The assistant can reason over available application facts such as wallet balance views, linked social accounts, promo/task history, support tickets, and FAQ content, then respond inside the Flutter support experience. Routine questions can be handled without always pulling in a human agent. When the issue needs a person, the flow can escalate into a human support ticket instead of pretending the model can resolve everything.
The same production direction extends into moderation: an AI-assisted content pipeline reviews social media (including image/reel classification with an ONNX NSFW model path), and behavior-oriented report handling can warn, escalate, or place social holds according to policy — with humans still in the loop for the harder cases. The support assistant does not modify balances, perform withdrawals, or act as a general write API over account records.
- Custom AI support assistant deployed in production
- Primarily read-oriented access to relevant user/account context
- Context-aware answers grounded in application data, not only chat history
- Escalation path to human support tickets when needed
- AI-assisted content moderation for social posts/reels
- AI-assisted behavior moderation / report handling with human oversight
Conversational AI becomes useful when it is connected to real application state — and honest about what it must escalate.
Telegram verification: solving the in-app requirement
Follow Pay needed a Telegram-related verification flow, but sending users outside the app created limitations around the verification experience. The requirement was to keep that flow inside Follow Pay.
I evaluated multiple Flutter/Telegram libraries, but they did not reliably satisfy the required flow. I then investigated handy_tdlib more deeply — including how it talked to TDLib/libtdjson — and developed a patch/adaptation that allowed the integration to work for our case.
The patched implementation was used in Follow Pay in production for approximately one year. After maintaining that work and noticing continued developer demand for a Flutter TDLib integration around the original handy_tdlib package, I later published the maintained approach as handy_tdlib_next — a community-maintained package, not an official Telegram or TDLib release.
Social + chat architecture
Later the product needed social features and chat. That introduced a completely different class of engineering problems. The architecture used Go, Dragonfly, WebSockets, REST APIs, and local storage. Dragonfly became part of the real-time and chat infrastructure.
The goal was to make chat feel closer to the responsiveness users expect from applications such as WhatsApp — not just “messages exist,” but that the state feels immediate and trustworthy.
The real-time race-condition problem
We had multiple sources of state that could update the same conversation or message nearly simultaneously: WebSocket real-time events, REST API responses, and local storage for cached or persisted client state.
That created race conditions. In practice I encountered local messages being wiped unexpectedly, duplicated messages, incorrect ordering or state, WebSocket events arriving before or after REST responses, and local state drifting away from server state.
The hard part was not making WebSockets work. The hard part was making multiple asynchronous sources of truth cooperate without corrupting local state.
Real-time systems are rarely difficult because of the WebSocket itself. They become difficult when multiple asynchronous systems believe they can update the same state.
How I worked through it
I had to reason about event ordering, local persistence, REST synchronization, WebSocket events, duplicate events, state reconciliation, race conditions, and the full message lifecycle.
After repeatedly reproducing and debugging the inconsistent states, I redesigned the synchronization behavior until the local state and real-time state behaved consistently. The work was less about a single clever trick and more about making the entire pipeline honest about who could mutate what, and when.
Technical architecture
Architecture evolved into multiple services and state layers
Not every request follows this exact linear path — this is the evolved service and state layering.
- Flutter + GetX
Client application and state management (including support UI)
- Local state / storage
Isar · SQLite · Hive
- API layer
FastAPI (self-hosted worker path)
- Backend services
Go chat/social backend
- PostgreSQL / Supabase
Data + RPC paths (including self-hosted Docker)
- Real-time infrastructure
Dragonfly + WebSockets (+ Asynq queues for moderation)
- AI support
Production support assistant with live account context + human escalation
- AI moderation
Content classification worker + behavior/report handling with human oversight
- Self-hosted delivery
Custom scripts + locally managed server deploy/runtime ownership
- Telegram / TDLib path
In-app verification via patched handy_tdlib work — later published as handy_tdlib_next
What this taught me
- Start simple, but design with the next bottleneck in mind.
- Production traffic reveals architectural assumptions.
- Managed infrastructure is convenient, but infrastructure ownership changes the trade-offs.
- Owning delivery scripts and the host environment makes deploy behavior inspectable.
- Support AI is valuable when it is grounded in application context and knows when to escalate.
- Moderation needs policy + human oversight, not only a model score.
- When libraries do not fit a production requirement, reading the integration layer carefully can unlock a workable path.
- Real-time applications require explicit state synchronization strategies.
- Debugging race conditions requires understanding the entire state pipeline, not just one component.