Skip to main content
WhatsApp Guides

Couchbase vs DynamoDB costs for WhatsApp chatbot session state

Sarah Jenkins
9 min read
Views 9
Featured image for Couchbase vs DynamoDB costs for WhatsApp chatbot session state

Building a WhatsApp chatbot requires a place to store the current status of a conversation. This is session state. Every time a user sends a message, your application needs to remember what happened in the previous message. If you ask a user for their email address, your database must store the fact that the next incoming message should be an email.

When your bot handles thousands of messages per minute, the database cost becomes a significant part of your budget. Two popular choices for this task are Couchbase and Amazon DynamoDB. Both handle JSON data well. Both offer high speed. Their pricing models differ in ways that change your monthly bill based on how many users talk to your bot.

Why session state costs matter in WhatsApp flows

WhatsApp webhooks trigger your backend for every interaction. A single user session might involve ten messages. If you have ten thousand active users, that is one hundred thousand database operations in a short window.

DynamoDB charges you for every individual read and write operation. Couchbase typically charges for the underlying server resources. If your bot has sudden spikes in traffic followed by long periods of silence, DynamoDB might be cheaper. If your bot has a high, steady volume of messages, Couchbase often provides a lower cost per operation.

Session data is usually small but accessed frequently. It also has a short lifespan. Once a user finishes a booking or a support ticket, you no longer need that session state in high-speed storage. You need a database that handles automatic expiration to keep costs down.

Prerequisites for choosing a session database

Before you pick a database, ensure you have these items ready:

  • A clear map of your chatbot conversation flow.
  • An estimate of your peak messages per second.
  • A developer account for AWS or Couchbase Capella.
  • A plan for data retention (e.g., sessions expire after 24 hours).
  • A backend service to process webhooks, such as n8n or a Node.js API.

Understanding DynamoDB pricing for chatbot sessions

DynamoDB uses a pay per use model or a provisioned capacity model. For a new WhatsApp integration, most developers start with the On-Demand mode.

Read and Write Capacity Units

In DynamoDB, you pay for Read Capacity Units (RCU) and Write Capacity Units (WCU).

  • One WCU handles a 1KB write per second.
  • One RCU handles a 4KB strongly consistent read per second.

WhatsApp session objects are usually under 1KB. This means every message your bot processes results in at least one write and one read operation. If your user sends a message, you read the state, update it, and write it back. That is two operations per user message.

The cost of On-Demand scaling

On-Demand pricing is approximately $1.25 per million write units and $0.25 per million read units. If your bot processes one million messages, you perform at least one million reads and one million writes. Your cost is roughly $1.50 per million messages for the operations alone. This excludes storage costs and data transfer fees.

Understanding Couchbase Capella pricing

Couchbase Capella is the managed cloud version of Couchbase. It uses a different philosophy. You pay for the instances that run the database. You do not pay for individual reads or writes.

Cluster based pricing

Couchbase pricing depends on the RAM, CPU, and Disk of your nodes. A small cluster might cost around $0.20 to $0.60 per hour per node. You usually need at least three nodes for a production environment to ensure high availability.

If your cluster costs $1.00 per hour in total, your monthly cost is about $720. This cost remains the same whether you process one thousand messages or ten million messages.

Memory First Architecture

Couchbase stores active data in RAM. This makes session lookups extremely fast. For WhatsApp bots where latency impacts user experience, this speed is a benefit. Because you pay for the hardware, you can push as much traffic as the CPU allows without increasing your bill.

Comparing the cost scenarios

Let's look at three different scales of WhatsApp chatbot activity to see which database wins on cost.

Scenario 1: The Low Volume Startup

Your bot handles 100,000 messages per month.

  • DynamoDB: At $1.50 per million operations, 100,000 messages cost pennies. You likely stay within the Free Tier limits for a long time.
  • Couchbase: A managed cluster still costs several hundred dollars per month even if it is mostly idle.

Winner: DynamoDB.

Scenario 2: The Mid Range Business

Your bot handles 10 million messages per month.

  • DynamoDB: 10 million messages cost approximately $15 for operations. Storage and backups might add another $5 to $10.
  • Couchbase: A small Capella cluster still costs around $500 to $700 per month.

Winner: DynamoDB.

Scenario 3: The High Volume Enterprise

Your bot handles 500 million messages per month.

  • DynamoDB: 500 million messages cost $750 in operations. Large scale deployments often require Global Tables or DAX (DynamoDB Accelerator) for speed, which can double or triple the cost.
  • Couchbase: That same $700 cluster might handle the load easily. As the volume grows, the cost per message in Couchbase drops toward zero.

Winner: Couchbase.

Implementation: Storing a WhatsApp session

Regardless of the database, your session schema should be simple. Use the user's WhatsApp ID as the primary key.

Example JSON Session Object

{
  "session_id": "1234567890",
  "current_step": "collect_email",
  "last_interaction": "2023-10-27T10:00:00Z",
  "captured_data": {
    "user_name": "John Doe",
    "product_interest": "Subscription"
  },
  "ttl": 1698400800
}

Example Node.js logic for DynamoDB

This code shows how to update a session state in DynamoDB. It uses the TTL attribute to ensure data expires automatically.

const { DynamoDBClient, UpdateItemCommand } = require("@aws-sdk/client-dynamodb");

const client = new DynamoDBClient({ region: "us-east-1" });

async function updateSession(userId, nextStep) {
  const expiration = Math.floor(Date.now() / 1000) + (24 * 60 * 60);

  const params = {
    TableName: "ChatbotSessions",
    Key: { "session_id": { S: userId } },
    UpdateExpression: "SET current_step = :s, expire_at = :t",
    ExpressionAttributeValues: {
      ":s": { S: nextStep },
      ":t": { N: expiration.toString() }
    }
  };

  await client.send(new UpdateItemCommand(params));
}

Example Node.js logic for Couchbase

Couchbase uses the upsert command. You can set the expiry directly on the document metadata.

const couchbase = require('couchbase');

async function updateSession(cluster, userId, nextStep) {
  const bucket = cluster.bucket('chatbot');
  const collection = bucket.defaultCollection();

  const sessionData = {
    session_id: userId,
    current_step: nextStep,
    last_interaction: new Date().toISOString()
  };

  // Set expiry for 24 hours (86400 seconds)
  await collection.upsert(userId, sessionData, { expiry: 86400 });
}

Handling High Frequency Spikes

WhatsApp marketing campaigns often cause massive spikes. If you send a broadcast message to 100,000 people, thousands will reply at the same time.

DynamoDB handles this with On-Demand scaling. It absorbs the spike without configuration, but you pay for every single request. Couchbase requires you to size your cluster for peak load. If your cluster is too small, latency increases. If it is too large, you pay for wasted capacity during quiet hours.

If you use a tool like WASender to manage your WhatsApp sessions via a standard account, you still need these external databases for logic. WASender handles the delivery and reception of messages, but your database manages the conversation flow.

Common edge cases

  • Oversized Sessions: If your session object grows larger than 4KB, DynamoDB costs double for that specific write. Couchbase does not penalize you for larger JSON objects in the same way, as long as you have enough RAM.
  • Frequent Polls: If your application polls the database to check for session timeouts instead of using built-in TTL, your DynamoDB costs will climb. Always use the native TTL features of your database.
  • Regional Latency: If your WhatsApp users are in Europe but your database is in the US, network latency adds up. Both Couchbase Capella and DynamoDB offer multi-region options, but these increase costs significantly.

Troubleshooting cost issues

High DynamoDB Bills

Check if your application is doing unnecessary reads. Sometimes a bug in the code might cause a loop that reads the same session state multiple times per message. Use the AWS Cost Explorer to see which specific table is driving the price. Ensure you are not using Provisioned Capacity with high minimums during periods of low traffic.

Slow Couchbase Performance

If your Couchbase session lookups are slow, check the Resident Ratio. This is the percentage of data stored in RAM. If this number drops, Couchbase must fetch data from the disk, which increases latency. You may need to upgrade your node size or add more nodes to the cluster.

FAQ

Which database is better for a small WhatsApp bot? DynamoDB is almost always better for small bots. The cost is negligible for low volumes, and there is no monthly server fee.

Does Couchbase offer a free tier? Couchbase Capella offers a free trial, and you can run Couchbase Server for free on your own hardware. However, managing your own servers adds labor costs.

Can I use Redis instead? Redis is excellent for session storage. It is very fast. However, Redis can be more expensive than DynamoDB for large amounts of data because everything must fit in RAM. It also lacks some of the complex querying features found in Couchbase or DynamoDB.

How does TTL work for cost saving? TTL (Time to Live) automatically deletes old data. In DynamoDB, deletions via TTL are free. In Couchbase, it clears up RAM and disk space, preventing you from needing a larger, more expensive cluster.

What if I need to store chat history and not just state? Session state is for the current conversation logic. Chat history is for long-term records. You should store chat history in a cheaper storage solution like Amazon S3 or a standard relational database and keep only the active state in your high-speed session database.

Final steps for your integration

Start with DynamoDB if you are building your first WhatsApp integration. The setup is fast and the initial cost is zero. Focus on building a resilient webhook handler that manages the session state correctly.

As your bot scales to millions of daily messages, perform a cost audit. If your DynamoDB bill starts to exceed the cost of a three-node Couchbase Capella cluster, plan a migration. Both databases use JSON, so the logic of your application remains mostly the same.

For those using developer tools like WASender to connect their WhatsApp accounts, remember that the database is the brain of your operation. Keep your session objects small, set your TTLs correctly, and monitor your usage monthly to avoid surprises.

Share this guide

Share it on social media or copy the article URL to send it anywhere.

Use the share buttons or copy the article URL. Link copied to clipboard. Could not copy the link. Please try again.