professional work

WhatsApp Session Infrastructure

Proxy pool, health monitoring, and auto-recovery for a production WhatsApp gateway.

Full-Stack Developer · Undisclosed · Oct 2025 — Present


context

The system used a WhatsApp gateway where each session was tied to a proxy IP. Sessions were failing unpredictably in production. Some failed right after a proxy repair, others got stuck in a restart loop. There was no error trail to work from.


the challenge

There were two separate failure modes happening at the same time. One was a webhook → restart → webhook loop that kept triggering itself. The other was sessions failing silently after repair even though the API returned 200 OK.


approach

  • 1.I added a cooldown lock on restarts. A repair worker can't restart a session that's already in a cooldown window, which breaks the loop.
  • 2.I found that the third-party API treats partial PUT bodies as a full replace, not a merge. So sending only the new proxy fields would wipe everything else. I changed the repair path to always GET the full config first, merge the new values, then PUT the complete body.
  • 3.I built a DB-backed proxy pool with a state machine (READY → ALLOCATED → RELEASED / REPAIRING) and used atomic DB increments for failure counters to fix a race condition where two cron runs were double-counting failures.

technical highlights

  • Session state is persisted in the DB. Repair workers read and write atomically, so concurrent repair attempts don't conflict.
  • The partial PUT issue was subtle. The API returns 200 OK either way, so the config wipe was completely silent. I only found it by tracing what the session config looked like after repair.
  • Repair workers run via Inngest and follow a proxy-swap → restart ladder. Each step checks the session is healthy before moving to the next.
  • I added an admin page with per-session event history so the repair lifecycle is visible without having to query the database directly.

result

The restart loop stopped. Silent post-repair failures stopped. Proxy swaps now go through the full GET → merge → PUT cycle correctly.


technologies

InfrastructurePostgreSQLDistributed SystemsInngest

Some implementation details have been generalized to respect employer confidentiality.