Caching and search

Typesense

Typesense is a fast C++ search engine with typo tolerance, facets and search-as-you-type that keeps its index in memory.

What it is

Typesense is an open source alternative to Algolia and a lighter option than Elasticsearch. It is written in C++ and keeps the index in RAM, so it answers in a few milliseconds.

You create a collection with a schema, load JSON documents and search over chosen fields. It has facets, grouping, geo search, synonyms and vector search. A multi-node cluster runs on the Raft protocol.

The code is open under GPL-3.0 and there is a hosted Typesense Cloud. Because the index sits in memory, dataset size is limited by RAM.

Use it when

  • You need instant search with facets for a site or app.
  • You want a self-hosted alternative to Algolia.
  • Your data fits into server RAM.

Avoid it when

  • Your data far exceeds available memory.
  • You need log analytics and complex aggregations: Elasticsearch or OpenSearch fit better.
  • The GPL-3.0 license does not suit your distribution scenario.

Key concepts

Collection / schema
A collection describes field types you can search, filter and sort by.
In-memory index
The index is loaded into RAM for minimal latency, with a copy kept on disk.
query_by
A query parameter listing the fields to search in.
Raft clustering
High availability comes from a cluster of 3 or 5 nodes using the Raft consensus algorithm.

Example

Creating a collection with a schema and a search with a typo.

Interview questions

  1. 1. How does Typesense differ from Elasticsearch?

    It is lighter, easier to set up and keeps the index in memory for minimal latency. Elasticsearch scales to huge volumes and suits logs and complex aggregations.

  2. 2. What is the main limit of Typesense?

    Data size is bounded by RAM because the index lives fully in memory. You must plan memory for collection size.

  3. 3. How is fault tolerance achieved?

    With a cluster of an odd number of nodes, usually three, running Raft: a majority confirms writes and the cluster keeps working when a node fails.

Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).