
SMS Gateway
Self-hosted SMS infrastructure that sends OTPs and transactional messages from a real SIM card.
- Role
- Sole engineer, end to end
- Company
- TriTech Solutions
- Surfaces
- Android sender · API · Web dashboard
- Used by
- Safar (OTP login)
The problem
Apps that log users in by phone need to send OTPs reliably and cheaply. SMS Gateway turns ordinary Android phones with SIMs into the sending devices. Products like Safar call a simple API, and a phone delivers the message.
How the pieces fit
- Client backendse.g. Safar, authenticated by API key
- Bun + Express APIQueueing, assignment, API keys, webhooks, delivery status
- PostgreSQLMessages, devices, SIMs, keys, logs
- Flutter sender appAndroid phones with SIMs; jobs over WebSocket, HTTPS polling as backup
- Next.js dashboardQR phone pairing, keys, webhooks, tracking
Highlighted = the part that links this project to the other case study.
What I built
- Flutter app that turns an Android phone into an SMS sender
- Kotlin plugin for dual-SIM sending with sent and delivered reports
- Bun + Express + PostgreSQL API
- QR-code pairing between phone and account
- API keys and signed webhooks for client apps
- Message tracking dashboard in Next.js
- Sends Safar's phone OTPs in production
The hard parts
Getting jobs to a phone
Phones never accept incoming connections. Each one keeps a WebSocket open to the server and gets new jobs in under a second. Android kills background sockets without warning, so the app also polls over HTTPS as a fallback, and a foreground service and boot receiver restart it after a crash or power cut.
Never sending a code twice
Each message carries one ID from the caller’s backend all the way to the phone. The phone saves the job before acknowledging it, and marks it “sending” before calling Android, so a repeated job is recognised and never resent. Once a phone has acknowledged a job, it is never handed to another phone.
Retries that cost money
Every retry is a real, paid SMS. A job is only retried while it is still waiting in the queue. If the app dies mid-send, the job is reported as unknown instead of being sent again: the user can tap resend, while two different codes would only confuse them. Status updates only move forward, so repeated reports are harmless.
Phones that look fine but can’t send
Jobs rotate across phones and their SIMs, least recently used first, claimed with FOR UPDATE SKIP LOCKED so two server processes never take the same job. A phone or SIM that keeps failing (no signal, no balance) is paused by a circuit breaker, tested with a single message on a backoff, and put back once that message goes through.
