idnasirasira
Back to works
102024currentLead Software Engineer

Knowledge Base Full-Text Search API (Rust)

Rust-powered search backend for a SaaS knowledge platform—indexes Markdown and HTML documentation at scale with Tantivy, exposes low-latency query APIs, and supports faceted filters, synonyms, and incremental re-indexing.

Loading views...

Overview

Built a dedicated full-text search service for a documentation-heavy SaaS product where teams publish internal guides, API references, and help articles. The existing database `LIKE` queries and Elasticsearch footprint were either too slow or too costly to operate at their scale. The Rust service watches content sources, parses and tokenizes documents, builds inverted indexes with Tantivy, stores document metadata in PostgreSQL, and serves ranked search results through a REST API consumed by the main web app. Designed as a stateless, horizontally scalable component with clear index versioning and safe rebuild workflows.

The Challenge

Search quality was poor: slow queries on large doc sets, no relevance ranking, and inconsistent results across Markdown vs HTML sources. Full re-indexes blocked writes and took hours. The team needed fuzzy matching, phrase search, category facets, and highlighting snippets for the UI—without ballooning infrastructure cost. Elasticsearch ops (cluster tuning, shard management) were a distraction for a small platform team. Any downtime during index rebuilds directly impacted customer-facing search in the product.

The Solution

Implemented an indexing pipeline in Rust that normalizes content (front matter stripping, heading extraction, slug generation), tokenizes with language-aware analyzers, and writes to Tantivy segments on disk with periodic commits. Exposed Axum endpoints for search, suggest/autocomplete, and admin re-index triggers. Used PostgreSQL for document registry, index generation metadata, and facet definitions; Redis for hot query caching and rate limiting. Added incremental indexing on content webhooks plus nightly consistency checks. Built blue/green index swap so new indexes go live atomically without search downtime.

Results & Impact

  • Indexed 50,000+ documents with p95 search latency under 80ms
  • 10x faster query response vs previous database full-scan approach
  • Cut search infrastructure cost by ~70% after moving off managed Elasticsearch
  • Zero-downtime index rebuilds via blue/green index swap
  • Improved click-through on top results with BM25 ranking and heading boosts
  • Incremental indexing reduced time-to-searchable for new docs from hours to minutes
  • Faceted filters (product, version, locale) adopted by 80%+ of active workspaces
  • Stable memory footprint under sustained query load during product launches

Key Features

  • Full-text search with BM25 relevance ranking
  • Phrase search, prefix matching, and fuzzy fallback for typos
  • Faceted navigation (product, version, locale, tags)
  • Search result highlighting snippets for UI preview
  • Autocomplete / typeahead suggestions endpoint
  • Markdown and HTML ingestion with front matter support
  • Incremental indexing via content publish webhooks
  • Scheduled full re-index with consistency validation
  • Blue/green index swap for zero-downtime deployments
  • Multi-tenant index isolation per workspace
  • Query caching and per-tenant rate limiting
  • Admin APIs: trigger re-index, index stats, health checks
  • Dockerized deployment with configurable index storage volumes

Want to build a system like these?

From ERP and logistics to web and mobile apps—I can help you design and build it. Get in touch to discuss your project.

Discuss your project