Skip to main content
BuilderBot provides multiple database adapters to persist conversation history and user data. Choose the adapter that best fits your infrastructure and scaling needs.

Available Adapters

MemoryDB

In-memory storage for development and testing

JSON File

Simple file-based persistence for small applications

MongoDB

NoSQL database for flexible, scalable storage

MySQL

Relational database with robust transaction support

PostgreSQL

Advanced relational database with rich features

Choosing a Database

MemoryDB

Best for:
  • Local development
  • Testing
  • Proof of concepts
  • Stateless bots (no persistence needed)
Limitations: All data is lost when the bot restarts.

JSON File Database

Best for:
  • Small bots with low traffic
  • Single-server deployments
  • Simple projects without database infrastructure
Limitations: Not suitable for high-concurrency or multi-server setups.

MongoDB

Best for:
  • Flexible schema requirements
  • Horizontal scaling
  • Document-oriented data
  • Cloud deployments (MongoDB Atlas)

MySQL

Best for:
  • Traditional relational data models
  • Existing MySQL infrastructure
  • ACID transaction requirements
  • Well-established hosting options

PostgreSQL

Best for:
  • Advanced SQL features
  • Complex queries and relationships
  • Contact management with custom fields
  • High-performance production environments

Common Interface

All database adapters extend the base MemoryDB class and implement these core methods:
interface DatabaseAdapter {
  // Get the last conversation state for a phone number
  getPrevByNumber(from: string): Promise<HistoryEntry | undefined>
  
  // Save a new conversation entry
  save(ctx: HistoryEntry): Promise<void>
}

Data Schema

Conversation history entries contain:
ref
string
required
Reference to the flow
keyword
string
Trigger keyword that initiated the flow
answer
string
required
The user’s response or message content
refSerialize
string
required
Serialized flow reference for state management
from
string
required
Phone number or user identifier
options
object
Additional metadata and flow options

Switching Adapters

Switching between adapters is straightforward - just change the import and initialization:
import { MemoryDB as Database } from '@builderbot/bot'

const adapterDB = new Database()

Next Steps

Quick Start

Set up your first bot with a database

Testing

Test your bot with different databases

Build docs developers (and LLMs) love