Back to selected work

FunnelChat: API layer, dashboard integrations and cloud migration

Engagement
FunnelChat API / Manager · client engagement through Setup Automatizado
Period
August 2025–present
Stack
  • Go
  • whatsmeow
  • WebRTC
  • MCP
  • OAuth 2.1
  • Next.js
  • TypeScript
  • Stripe
  • NATS JetStream
  • PostgreSQL
  • Redis
  • Terraform
  • AWS
  • OCI
  • Kubernetes
  • Prometheus
  • Grafana
FunnelChat APIConcept diagram · simplified
  1. Instance events
  2. Go API
  3. NATS JetStream lanes
Serial events
Receipts

Serial-event gateClient delivery

Earlier serial events gate receipt dispatch. Receipt callbacks have no total ordering.

In 30 seconds

Problem

The messaging product needed an API, a subscription dashboard and infrastructure that could scale without treating cost and security as separate projects.

My part

Through Setup, I built and evolved the Go API layer on whatsmeow with Z-API-compatible endpoints. I integrated browser calls through WebRTC and an embedded VoIP engine, implemented SaaS dashboard features and led the application’s migration from AWS to Oracle Cloud Kubernetes.

Result

The implementation connects messaging, configurable subscription pricing and deployment controls. Autoscaling and clustered state services support an architecture designed for thousands of instances.

How it works

  1. Instance events

    Messages, status changes and delivery receipts arrive from each WhatsApp instance.

  2. Go API

    Separates delivery receipts from the serial event path.

  3. NATS JetStream lanes

    Serial events keep one ordered path; receipts get a dedicated durable consumer. After a restart, a worker adopts the existing consumer and keeps its position.

  4. Lane admission

    Workers admit each delivery through a PostgreSQL coordination point for its lane.

  5. Serial-event gate

    Earlier serial events of the instance must be sent before a receipt is dispatched.

  6. Client delivery

    Delivery uses the admission fence for earlier serial events. Receipt callbacks may arrive out of order relative to one another; an in-flight receipt may arrive after a later callback.

Receipt dispatch waits until earlier serial events of the instance have been sent. Receipt callbacks may arrive out of order among themselves, and a receipt already in flight may arrive after a later callback.

Technical decisions

  1. Build the API layer on whatsmeow and implement Z-API-compatible contracts.

    Why
    The implemented endpoints and events expose messaging, campaigns and media through familiar REST contracts.
    Trade-off
    Endpoint compatibility and upstream library changes need separate maintenance; the library remains its authors’ work.
  2. Lead the application’s migration from the AWS foundation to Oracle Cloud Kubernetes.

    Why
    Autoscaling, shared state and explicit deployment controls support the target architecture.
    Trade-off
    Kubernetes configuration introduces database/broker recovery, capacity and field-ownership responsibilities.
  3. Use narrow browser call tickets and immutable image references.

    Why
    A browser call needs scoped access; deployment needs an identifiable artifact.
    Trade-off
    Ticket redemption depends on shared state, and releases must pass image-identity checks.

Operation

I built the initial AWS foundation with Terraform for ECS Fargate, RDS, ElastiCache, S3 and CloudFront, and wrote owner-aware ECS request routing in Go. For the application’s OKE migration, I configured pod/node autoscaling, NATS JetStream, PostgreSQL/CloudNativePG, Redis Sentinel, observability and deployment/network controls. Cost work included ARM64 application-image builds, right-sizing, OCI Object Storage in place of in-cluster MinIO and an autoscaling proxy mesh. Implemented security controls include single-use call tickets, SSRF protection, signed images, digest-pinned deployments and default-deny networking.

Authorship

I built and evolved the application’s API layer on whatsmeow and implemented dashboard features and integrations. Browser calls use a WebRTC bridge and an embedded third-party VoIP engine. I also reviewed and integrated multi-author releases, retaining the original contributors’ authorship.

Build the API around the product contract

I built and evolved FunnelChat’s WhatsApp API layer in Go on the whatsmeow library, implementing REST contracts and events compatible with the Z-API endpoints covered by that work. The application layer adds messaging, campaigns, media handling and webhook delivery. My engagement is through Setup Automatizado and began in August 2025. The work grew to include browser-call integration, an MCP server, SaaS dashboard features and infrastructure migration. The product boundary matters: whatsmeow supplies the underlying library; my contribution is the API layer and integrations that expose its capabilities to the product.

Give delivery a record it can recover from

Webhook delivery uses an outbox, a dead-letter queue and at-least-once semantics. A delivery can be attempted again, so recovery needs persistent state rather than an assumption that a successful network write settles everything. I worked on NATS JetStream consumers and the PostgreSQL delivery ledger, including startup recovery when consumer creation times out after the broker has already created it. The recovery path can adopt the existing durable consumer and preserve its start position. It uses bounded retries, with cancellation interrupting the backoff during shutdown.

Keep concurrency tied to a specific boundary

Receipts have a separate processing path that waits until earlier serial events for the instance have been sent. This is a dispatch condition, not a total ordering of callbacks. Receipt callbacks may arrive out of sequence, and one already in flight can arrive after a later callback. I implemented the consumer and its acknowledgement-position check while retaining serial processing as the default. The configurable split adds consumer lifecycle, draining state and database coordination per lane. Those costs belong to the concurrency decision rather than disappearing behind a queue.

Bring calls and agent access into the API

I integrated browser voice and video calling through a WebRTC bridge and an embedded third-party VoIP engine, alongside an OAuth 2.1 MCP server for explicit agent access to the API. Browser call streams use a signed, short-lived ticket bound to the instance and call instead of the instance credential. Redis coordinates one-time redemption across replicas. A store failure refuses the stream request. The browser obtains a ticket when it is about to open the stream, so a microphone permission prompt does not consume its validity window beforehand.

Make the dashboard part of the product

I implemented features in the Next.js SaaS dashboard and its Stripe integration, supporting subscription and invoice workflows with configurable BRL, USD and EUR prices. The interface and emails include Portuguese, English and Spanish localization. I also changed authentication integration so session listings and authentication responses do not need to expose underlying session tokens. Revocation resolves a session ID on the server and checks that it belongs to the signed-in user. These controls sit in the dashboard’s integration with the authentication service. The pricing implementation selects the requested currency when configured and otherwise falls back to the canonical price.

Keep contracts usable across the interface

The API and dashboard had to agree on authentication and call access. I changed server-side actions to obtain the call ticket and return the authorized stream address, with the TypeScript client generated from the API specification. This connects the browser interaction to the backend contract. It also gives changes a defined place to land: an API shape, an authorization check and the interface action that consumes them.

Separate infrastructure provisioning from request routing

The earlier AWS implementation used Terraform to provision ECS Fargate, RDS, ElastiCache, S3 and CloudFront. I added media delivery through CloudFront Origin Access Control and S3 policies. Request ownership was a different problem: an instance could belong to a particular ECS worker, so the request needed to reach that worker. I wrote the owner-aware routing in Go, using an internal reverse proxy and an explicit unavailable response when the owning worker could not be reached. Terraform managed the infrastructure; Go made the application routing decision.

Move to Kubernetes with shared state and clear ownership

I built the initial AWS infrastructure and led the application’s migration to Oracle Cloud Kubernetes Engine. I configured pod and node autoscaling, a NATS JetStream cluster, PostgreSQL with CloudNativePG, Redis Sentinel and Prometheus/Grafana observability. The architecture is designed for thousands of instances, with load-test scenarios and a harness. Kubernetes field ownership needed attention: deployment automation must not overwrite replica counts managed by the horizontal pod autoscaler. I corrected that boundary and retained digest-based image checks, while integrating reviewed network policies, disruption budgets and alerting changes.

Work on cost through concrete resource choices

Cost was an objective of the infrastructure work. I adapted the application-image builds for ARM64, right-sized resources and replaced the application’s in-cluster MinIO storage with OCI Object Storage. I also implemented an autoscaling proxy mesh. These are concrete changes to application compute, storage and proxy capacity. They also affect operations: architecture-specific application images constrain placement, and autoscaling needs capacity rules as well as deployment code. The configuration work connects these resource choices with shared services, recovery paths and deployment controls.

Apply security at the boundaries that carry authority

Single-use call tickets, server-side session ownership checks and SSRF protection constrain what a caller can request or receive. Signed images, digest-pinned deployments and default-deny networking add controls around delivery and service communication. My work covered both implementation and release integration. Where a release contained other contributors’ commits, I preserved their authorship and treated review and integration as separate responsibilities. Together, the API, dashboard and infrastructure show the scope of my role: build the product, handle failure boundaries and keep access and operational cost visible in the design.

Discuss an engineering role

Open to on-site and hybrid opportunities throughout Spain, and remote opportunities in Europe.

contato@guilhermejansen.com

Guilherme Jansen · Senior Software Engineer · AI Engineer

Back to top