Typesense + HA Cluster
Fast, typo-tolerant search engine built in C++.
Overview
Typesense is a modern, open-source search engine built in C++ that delivers instant search experiences with built-in typo tolerance. Originally created as a developer-friendly alternative to complex solutions like Elasticsearch, Typesense focuses on simplicity without sacrificing performance, offering sub-millisecond search responses and intuitive APIs that make implementation straightforward for developers.
This three-node high availability cluster configuration leverages Typesense's built-in Raft consensus protocol to ensure search service continuity and data consistency across all nodes. The cluster automatically handles leader election, data replication, and failover scenarios, providing enterprise-grade reliability while maintaining Typesense's signature fast response times. Each node can serve read requests independently, distributing query load effectively.
This setup is ideal for production environments requiring zero-downtime search capabilities, such as e-commerce platforms with high traffic volumes, SaaS applications with critical search functionality, or content-heavy websites where search availability directly impacts user experience. The three-node configuration provides the optimal balance between fault tolerance and resource efficiency, surviving single node failures while maintaining quorum.
Key Features
- Typo-tolerant search with automatic error correction for misspelled queries
- Sub-millisecond search response times with in-memory indexing
- Raft consensus protocol for automatic leader election and data consistency
- Real-time faceted search and filtering across multiple attributes
- Geo-search capabilities for location-based queries and radius filtering
- Synonym support and result curation for enhanced search relevance
- Vector search functionality for semantic and AI-powered search experiences
- Automatic cluster healing and node recovery without manual intervention
Common Use Cases
- 1E-commerce product search with instant autocomplete and faceted filtering
- 2SaaS application search requiring 99.9% uptime and fast response times
- 3Content management systems with large document repositories
- 4Real estate platforms combining text search with geographical filtering
- 5Job boards requiring complex filtering across multiple job attributes
- 6Knowledge base search for customer support and documentation sites
- 7Multi-tenant applications where search downtime affects multiple customers
Prerequisites
- Minimum 3GB RAM total (1GB per node) for optimal cluster performance
- Docker and Docker Compose 3.8+ with networking support enabled
- Available ports 8108 (API) and 8107 (peer communication) for cluster coordination
- Understanding of API key management and secure credential storage
- Basic knowledge of search indexing concepts and JSON document structures
- Network connectivity between nodes for Raft consensus communication
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 typesense-1: 3 image: typesense/typesense:latest4 environment: 5 - TYPESENSE_API_KEY=${API_KEY}6 - TYPESENSE_DATA_DIR=/data7 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:81078 volumes: 9 - typesense-1-data:/data10 ports: 11 - "8108:8108"12 networks: 13 - typesense-network14 restart: unless-stopped1516 typesense-2: 17 image: typesense/typesense:latest18 environment: 19 - TYPESENSE_API_KEY=${API_KEY}20 - TYPESENSE_DATA_DIR=/data21 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:810722 volumes: 23 - typesense-2-data:/data24 networks: 25 - typesense-network26 restart: unless-stopped2728 typesense-3: 29 image: typesense/typesense:latest30 environment: 31 - TYPESENSE_API_KEY=${API_KEY}32 - TYPESENSE_DATA_DIR=/data33 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:810734 volumes: 35 - typesense-3-data:/data36 networks: 37 - typesense-network38 restart: unless-stopped3940volumes: 41 typesense-1-data: 42 typesense-2-data: 43 typesense-3-data: 4445networks: 46 typesense-network: 47 driver: bridge.env Template
.env
1# Typesense Cluster2API_KEY=your-api-key-here34# 3-node cluster for high availability5# Raft consensus for leader electionUsage Notes
- 1API at http://localhost:8108
- 23-node HA cluster
- 3Raft consensus
- 4Sub-millisecond latency
- 5Typo tolerance built-in
Individual Services(3 services)
Copy individual services to mix and match with your existing compose files.
typesense-1
typesense-1:
image: typesense/typesense:latest
environment:
- TYPESENSE_API_KEY=${API_KEY}
- TYPESENSE_DATA_DIR=/data
- TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:8107
volumes:
- typesense-1-data:/data
ports:
- "8108:8108"
networks:
- typesense-network
restart: unless-stopped
typesense-2
typesense-2:
image: typesense/typesense:latest
environment:
- TYPESENSE_API_KEY=${API_KEY}
- TYPESENSE_DATA_DIR=/data
- TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:8107
volumes:
- typesense-2-data:/data
networks:
- typesense-network
restart: unless-stopped
typesense-3
typesense-3:
image: typesense/typesense:latest
environment:
- TYPESENSE_API_KEY=${API_KEY}
- TYPESENSE_DATA_DIR=/data
- TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:8107
volumes:
- typesense-3-data:/data
networks:
- typesense-network
restart: unless-stopped
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 typesense-1:5 image: typesense/typesense:latest6 environment:7 - TYPESENSE_API_KEY=${API_KEY}8 - TYPESENSE_DATA_DIR=/data9 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:810710 volumes:11 - typesense-1-data:/data12 ports:13 - "8108:8108"14 networks:15 - typesense-network16 restart: unless-stopped1718 typesense-2:19 image: typesense/typesense:latest20 environment:21 - TYPESENSE_API_KEY=${API_KEY}22 - TYPESENSE_DATA_DIR=/data23 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:810724 volumes:25 - typesense-2-data:/data26 networks:27 - typesense-network28 restart: unless-stopped2930 typesense-3:31 image: typesense/typesense:latest32 environment:33 - TYPESENSE_API_KEY=${API_KEY}34 - TYPESENSE_DATA_DIR=/data35 - TYPESENSE_NODES=typesense-1:8108:8107,typesense-2:8108:8107,typesense-3:8108:810736 volumes:37 - typesense-3-data:/data38 networks:39 - typesense-network40 restart: unless-stopped4142volumes:43 typesense-1-data:44 typesense-2-data:45 typesense-3-data:4647networks:48 typesense-network:49 driver: bridge50EOF5152# 2. Create the .env file53cat > .env << 'EOF'54# Typesense Cluster55API_KEY=your-api-key-here5657# 3-node cluster for high availability58# Raft consensus for leader election59EOF6061# 3. Start the services62docker compose up -d6364# 4. View logs65docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/typesense-cluster/run | bashTroubleshooting
- Cluster shows split-brain behavior: Ensure all three nodes have identical TYPESENSE_NODES configuration and can communicate on port 8107
- Node fails to join cluster with 'peer not found' error: Verify Docker network connectivity and that all containers are on the typesense-network
- Search queries return stale data: Check cluster status endpoint to confirm leader election completed and data replication is current
- High memory usage during indexing: Increase Docker container memory limits and consider batch sizing for large document imports
- API returns 503 service unavailable: Verify cluster quorum exists with at least 2 of 3 nodes healthy and check API_KEY environment variable
- Slow query performance in cluster: Monitor which node is handling requests and consider load balancing across healthy nodes
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Components
typesense-1typesense-2typesense-3
Tags
#typesense#search#full-text#clustering#high-availability
Category
Database StacksAd Space
Shortcuts: C CopyF FavoriteD Download