DEV Community

botsense seo
botsense seo

Posted on

Building a WhatsApp Business API Platform in India: Technical Architecture & Lessons Learned

When we started building BotSense.io, India's WhatsApp Business API platform, we had no idea how technically complex it would get. Two years later, here's a breakdown of our architecture and key technical lessons — for any developer building on the WhatsApp Business API.

The Stack

  • Backend: Node.js with Express (webhook handlers), Python for AI/NLP pipeline
  • Database: PostgreSQL for structured data, Redis for session/conversation state
  • Queue: Bull (Redis-based) for message processing — critical for rate limiting
  • Infra: AWS (EC2, RDS, ElastiCache), load-balanced across regions
  • Meta Integration: WhatsApp Business API via Meta Cloud API (v18+)

The Core Challenges

1. Webhook Reliability

WhatsApp sends webhooks for every message/status update. At scale, you WILL miss messages if you:

  • Process synchronously in the webhook handler
  • Don't implement idempotency (Meta retries failed webhooks)
  • Don't return a 200 immediately before processing

Our solution: Webhook handler does nothing except push to a Redis queue and return 200. A separate worker pool processes the queue.

app.post('/webhook', (req, res) => {
  res.sendStatus(200); // Always respond immediately
  messageQueue.add(req.body); // Process async
});
Enter fullscreen mode Exit fullscreen mode

2. Rate Limiting

Meta enforces strict rate limits per phone number. Exceeding them gets your number flagged.

Key limits to know:

  • Business-initiated conversations: limited per 24h window based on tier
  • Message templates: must be pre-approved, no improvisation

3. Session Management

A conversation has a 24-hour window from the last user message. After that, you can only send approved templates, not freeform messages.

We use Redis TTL keys to track conversation windows:

const sessionKey = `session:${phoneNumber}`;
const ttl = 86400; // 24 hours
await redis.setex(sessionKey, ttl, JSON.stringify(conversationState));
Enter fullscreen mode Exit fullscreen mode

4. Message Template Management

Templates need approval and can take 24-72 hours. Build your template library early, use variables wisely, and never hardcode content that might change.

Results After 2 Years

  • 200+ active SMB clients on the platform
  • 60% reduction in average customer response time
  • 35% cart recovery rate for ecommerce clients
  • Official Meta Business Partner certification

Key Takeaways

  1. Queue everything — synchronous webhook processing will break you
  2. Cache conversation state — database reads on every message don't scale
  3. Template library is a product — invest time building good templates
  4. Monitor your message quality rating — Meta will limit you if users block your number

Happy to answer questions in the comments. Building on WhatsApp API in India has been a wild ride but the market opportunity is enormous — 60M+ SMBs with zero CRM infrastructure but 100% WhatsApp penetration.

Top comments (0)