Skip to content

Search Architecture

ServerlessInbox provides full-text search over email content using Tantivy, a Rust search library, embedded directly into the request path rather than run as a separate search service.

Every account has its own Tantivy index. There is no shared or cross-account index. The index is stored as a single archive in the same S3 bucket used for email blobs and attachments, at:

accounts/{accountId}/search-indexes/account-index.tar.gz

Because the index lives alongside the account’s other data in the same bucket, there’s no separate index bucket or bucket name to provision or track — just a distinct key prefix within the existing per-account storage.

Building the index: a scheduled, incremental rebuild

Section titled “Building the index: a scheduled, incremental rebuild”

The tantivy-indexer Lambda is triggered on a fixed EventBridge schedule, every 6 hours — not by an event from email delivery or an SQS queue. On each run it works through accounts and, for each one, compares the changelog state recorded the last time that account’s index was built against the changelog’s current state:

  • If nothing has changed for the account since the last run, it’s skipped — no rebuild work, no S3 write.
  • If there are changes, the indexer performs an incremental update: it fetches the changed items from DynamoDB, updates the Tantivy index in memory, and writes the updated archive back to S3.

This keeps steady-state cost low — most accounts have no new mail in a given 6-hour window and cost nothing to “check.”

Serving a query: index + changelog, merged

Section titled “Serving a query: index + changelog, merged”

Full-text search is performed in-process inside the jmap-api Lambda, not by invoking a separate search Lambda. jmap-api is Go with a CGO bridge into the Tantivy library, and holds a read-only S3 grant (grantSearchIndexRead) to fetch and open an account’s index directly.

A search query does not rely solely on the on-disk index — which may be up to 6 hours stale — for its results. Instead, jmap-api runs two searches in parallel and merges them:

  1. Tantivy search against the account’s S3-backed index, covering everything indexed as of the index’s last-recorded changelog state.
  2. Changelog-based search against DynamoDB, covering every change recorded after that state — i.e. mail that arrived, or was modified, since the index was last built.

The two result sets are merged before being returned. This means a query finds mail that arrived seconds ago even though the index itself might not be rebuilt for hours: freshness comes from pairing the index with a live read of the changelog, not from indexing latency.

If the changelog no longer recognizes the index’s cached last-indexed state (the gap is too large — for example, changelog entries have expired via TTL), the search retries by re-fetching the index’s current state fresh rather than serving a stale comparison.

  • The index is per account, not per mailbox or global. A query never searches across accounts, and there’s no cross-account or cross-tenant index to reason about.
  • A rebuild is per-account and incremental, not a full re-index every cycle — cost and duration scale with how much a given account changed since its last run, not with total mailbox size.
  • Freshness is bounded by the changelog, not the rebuild interval. As long as the changelog still recognizes the index’s last-indexed state, results include everything up to the moment of the query. The rebuild schedule exists to keep the changelog-side scan small, not to bound freshness.