Prompt
How do I choose a search provider for an app with filters and permissions?
Latest observation
A good search provider for an app with filters and permissions should be chosen based on three things:
- How you’ll store and query data
- How complex your filters are
- How permissions must be enforced
Here’s a practical way to decide.
1) Start with your requirements
Ask:
- Data size: thousands, millions, or billions of records?
- Search type: keyword search, faceted filters, full-text search, autocomplete, typo tolerance?
- Filter complexity: simple equality filters, ranges, nested fields, dynamic facets?
- Permissions: per-user, per-team, per-organization, row-level security, document-level ACLs?
- Freshness: does search need to update instantly or can it lag a few seconds/minutes?
- Operational burden: do you want a managed service or self-hosted?
- Compliance/security: can sensitive data leave your primary DB?
2) Match provider type to your needs
Use your primary database if:
- You have modest data volume
- Search is simple
- Permissions are straightforward
- You want the simplest architecture
Examples:
- PostgreSQL full-text search
- Postgres with indexes + JSONB filters
- MySQL full-text search
Pros: easiest consistency with permissions, fewer moving parts
Cons: weaker relevance, faceting, typo tolerance, and scaling for search-heavy workloads
Use a search engine if:
- You need strong text search, ranking, facets, autocomplete
- You have many searchable fields and filters
- Search traffic is high
Examples:
- Elasticsearch / OpenSearch
- Meilisearch
- Typesense
- Algolia
Pros: built for search UX, fast filtering/facets, relevance tuning
Cons: permission logic is harder, usually eventual consistency, extra sync pipeline needed
3) Permissions are the real deciding factor
If users only see data they’re allowed to access, your provider must support one of these patterns:
A. Filter-by-permission at query time
Store permission attributes on each document, such as:
tenant_idorg_idteam_idsvisibilityallowed_user_ids
Then every query includes permission filters.
Best for: multi-tenant apps, team-based access
Watch out: large allowed_user_ids lists can get expensive
B. Precompute searchable visibility
Index separate documents or shards per tenant/org/role.
Best for: strong tenant isolation
Watch out: duplication and index growth
C. Search IDs first, authorize second
Use search to find candidate IDs, then check permissions in the app or DB before returning results.
Best for: when permissions are too complex to index cleanly
Watch out: can hurt performance and ranking consistency
D. Hybrid approach
Use search engine for retrieval, primary DB for authorization.
This is common and often safest.
4) Provider-specific guidance
PostgreSQL
Choose this if:
- You want a simpler stack
- Permissions are tightly tied to relational data
- Search quality needs are moderate
Good for:
- Internal tools
- SaaS apps with moderate search needs
- Apps where consistency matters more than fancy search features
Elasticsearch/OpenSearch
Choose this if:
- You need advanced filtering/facets and large-scale search
- You can maintain sync pipelines
- You can model permissions in search documents
Good for:
- Enterprise content search
- Large catalog/search experiences
- Log/event/document search
Algolia
Choose this if:
- You want great UX quickly
- You need hosted managed search
- You can afford usage-based pricing
Good for:
- E-commerce
- Content discovery
- Fast time-to-market
Meilisearch/Typesense
Choose this if:
- You want simpler ops than Elasticsearch
- You need good search UX
- Your permission model is manageable
Good for:
- Mid-sized apps
- Product catalogs
- Internal search tools
5) A simple decision rule
- Simple permissions + moderate search: PostgreSQL
- Complex search + scalable filters + manageable ACLs: OpenSearch/Elasticsearch
- Fastest implementation and managed UX: Algolia
- Simpler self-hosted search with good UX: Meilisearch or Typesense
6) Don’t forget these design details
For filters and permissions, make sure the provider supports:
- Boolean filters
- Range filters
- Multi-value facets
- Stable pagination
- Tenant scoping
- Excluding unauthorized records
- Incremental reindexing
- Soft deletes
- Auditability
7) Recommended architecture in many apps
A common pattern is:
- Primary DB = source of truth + permissions
- Search provider = indexed copy for fast query/filtering
- App layer = enforces permissions and handles fallback checks
This gives you:
- Good search UX
- Correct access control
- Easier debugging
8) If you’re unsure, choose based on this priority order
- Correctness of permissions
- Query/filter needs
- Operational simplicity
- Search quality
- Cost
If permissions are tricky, favor a design where the primary DB remains the authority and the search provider only speeds up retrieval.
If you want, I can also help you choose between Postgres vs Elasticsearch vs Algolia vs Meilisearch based on your exact app.