# Running Typesense in Production
In addition to performance and ease-of-use, Typesense is also designed to have low operational overhead in Production.
When running Typesense in Typesense Cloud (opens new window), running in production is as simple as flipping a switch to enable "High Availability" and you'll have a distributed multi-node cluster that is production-ready and ready-to-use.
Typesense is a single self-contained binary with no runtime dependencies. So when self-hosting, running Typesense in Production involves simply installing Typesense, starting the Typesense process as a daemon, either via Docker or a process manager (our DEB and RPM packages do this for you) and configuring High Availability as needed.
# Production Best Practices
Here are a couple of pointers to ensure that you get an optimal experience from Typesense in Production.
TIP
Most of the server infrastructure related items are not applicable to Typesense Cloud clusters, since we manage the infrastructure for you.
# Configuration
- Ensure that you have picked the right system configuration for your dataset and traffic patterns.
- Typesense comes built-in with a high performance HTTP server (opens new window) that is used by likes of Fastly (opens new window) in their edge servers at scale.
So Typesense can be directly exposed to incoming public-facing internet traffic, without the need to place it behind another web server like Nginx / Apache or your backend API.
- Typesense also has a robust authentication mechanism that lets you configure Role-Based Access to a subset of data for particular users, should you need it.
- Enable CORS using the
--enable-cors
server parameter should you need it. (We manage this for you in Typesense Cloud (opens new window)).
- Run a Highly-Available cluster when serving Production traffic (optional, but highly recommended).
- Make sure that you have configured your API clients to use all nodes in your cluster.
- If you're using the Search Delivery Network (SDN) option in Typesense Cloud (opens new window), make sure that you have configured the clients appropriately to use the SDN endpoint, along with the individual hostnames to use as fallback.
- Configure a minimal amount of swap space for safety reasons, but if you see swap being used, that will start affecting performance and is a sure sign that you'd need to upgrade RAM capacity.
- If you're integrating Typesense with a mobile app, we highly recommend that you store the Typesense hostnames and API Key(s) on your backend, and have your app dynamically fetch the remote configs on load, instead of hard-coding these in the app. This is helpful if you need to change the hostnames / API keys for any reason. With remote configs, you can change these values without having to go through a round of app store review processes.
# Monitoring
- Monitor the
/health
API endpoint for uptime. - Monitor RAM usage to ensure that it is below 85% of total RAM - you want to ensure that the OS has sufficient RAM to do its thing.
- You can access memory usage metrics via the
/metrics.json
endpoint or via the Typesense Cloud Dashboard.
- You can access memory usage metrics via the
- Monitor the
/stats.json
API endpoint for request rate and latency. - Monitor CPU usage to ensure that it is below 90% on average. If it spikes beyond that, you might need to upgrade to higher CPU capacity.
- You can access CPU usage metrics via the
/metrics.json
endpoint or via the Typesense Cloud Dashboard.
- You can access CPU usage metrics via the
- When using the
import
API to ingest large batches of data, make sure that you have configured a sufficiently high timeout value to let your large imports complete, since all write operations are synchronous in Typesense.
# Search Relevance
- Setup search analytics.
- Monitor the search terms users are using, and setup synonyms as appropriate.
- Monitor the search terms users are using, and curate results as needed.
- While Typesense's default relevance parameters work out-of-the-box for majority of use cases, you can also fine-tune search relevance parameters as needed.
- While
default_sorting_order
is optional, it is highly recommended especially if you have a field in your documents that is a proxy for how popular a document is within your dataset.
- While
# Security
- Set
--api-port
server parameter to443
and useHTTPS
in production.- Ensure that your firewall only allows inbound public traffic via this port.
- Configure your SSL certificate and key using the
--ssl-certificate
and--ssl-certificate-key
parameters.
- When running a Highly-Available cluster, ensure that the
--peering-address
parameter is an IP Address on your INTERNAL private network. - Ensure that you have a strategy for expiring and rotating API keys regularly, using the
expires_at
parameter. - If you are storing multi-tenant data in a single collection, ensure that you have configured your Scoped Search API Keys correctly, to include the logged-in user's ID in the embedded filter.
- Scoped Search API Keys need to be generated in your backend stack, and passed on to the frontend which should then send that to Typesense in API Calls.
- Be sure to never expose your parent Search API Key to users, since that key has unrestricted access to all records.
- On Typesense Cloud, set up a team account to manage access and setup Single Sign-On.
# Schema Management
- Set up a collection alias and use the alias to access the collection and documents from your application.
- This is especially helpful when you need to update the schema of a collection. You'd create a new timestamped collection, re-index your data in it and then swap the alias to point to it.
- Prefer a pre-defined schema when possible, since with auto-schema detection, you might end up accidentally indexing fields that you might not be using for search purposes in memory, taking up RAM unnecessarily (unless you explictly set
index: false
on those fields). But you can also use Regex fields name and auto schema detection especially when field names are dynamic. - Ensure that fields you're using only for display purposes (eg: image URL, links, etc) are not specified in the schema (or set as
index: false
when using auto-schema detection), in order to set these fields as unindexed fields and save memory. You can still send these unindexed fields in the documents when adding them to the collection - they will just be stored on disk, and will not take up any memory. Then when that document is a hit, these unindexed fields will be fetched from disk, and stuffed into the search API response for you to use for display purposes.
# Staying Up-To-Date
- To get updates when new versions of Typesense are released, click on "Watch" → "Custom" → "Releases" in the Typesense GitHub repository (opens new window).
- Follow these update instructions to update to the latest version.
- We also post updates on Twitter @typesense (opens new window) and in our Slack Community (opens new window).
# Support
We've strived to keep Typesense as self-service and out-of-the-box as possible, with fully public documentation.
But if you need help or have any questions, here are a couple of ways to seek additional help:
- Read through our Frequently Asked Questions or browse through the nav bar on the left-pane in our Guide for relevant articles - we've put these articles together based on feedback from several users.
- Use GitHub's native search to search through past conversations in our GitHub issue tracker (opens new window).
- Browse and search through past conversations (opens new window) in our Slack community.
- Open a GitHub issue (opens new window) with any questions or bug reports.
- Join our public Slack community (opens new window) to discuss general questions and/or issues.
- Schedule a call with a member of the core Typesense team, by sponsoring Typesense on GitHub (opens new window) and picking the appropriate one-time sponsorship tier, and email us at contact at typesense dot org
- We also offer prioritized paid support, with private Slack, email & phone-based support with guaranteed SLAs on Typesense Cloud. Learn more here (opens new window).