---
title: "Deploy Typesense Rails"
description: "Instant search for Rails models with the typesense-rails gem"
category: "Analytics"
url: https://railway.com/deploy/deploy-typesense-for-ruby-on-rails
---

# Deploy Typesense Rails

Instant search for Rails models with the typesense-rails gem

**[Deploy Typesense Rails on Railway](https://railway.com/template/deploy-typesense-for-ruby-on-rails)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/deploy-typesense-for-ruby-on-rails/manifest.json

- **Creator:** onepush
- **Category:** Analytics

## Template content

### typesense-railway

- **Source:** Shinyduo/typesense-railway
- **Public domain:** Yes

## Documentation

# Deploy and Host self hosted Typesense Rails (Instant Search for Ruby on Rails) on Railway

Got a Rails app where search is just a slow LIKE query? It's aimed at Rails developers who want typo-tolerant search without a SaaS bill.

## About Hosting Typesense Rails open-source software on Railway (self hosted Typesense template)

Typesense Rails is the official typesense-rails gem, a Ruby on Rails integration for the Typesense search engine that works with ActiveRecord, Sequel and Mongoid models.

This Railway template runs a Typesense 30 image behind a small Caddy proxy on PORT 8080, forwarding to Typesense on 127.0.0.1:8118.

## Why Deploy Typesense Rails, the Algolia alternative on Railway (Railway Free Trial)

Algolia bills per search request and per record, so a busy Rails app can get pricey fast. You own uptime, backups, and the admin key.

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Typesense Rails on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

### Railway vs Other Hosting Providers and VPS for Typesense Rails self hosting

Typesense Rails needs one always-on search node next to your Rails app, so the question is what you pay for it and how much upkeep it takes. The table compares them.

| Provider | What You Get with Railway | What You Get with the Other Provider |
| --- | --- | --- |
| DigitalOcean | A Typesense service built from the Shinyduo/typesense-railway repo, with a volume and public HTTPS domain set up. | A Droplet you manage, including Docker, DNS, TLS, and volume config. |
| AWS | A private URL for your Rails app and a public domain for browsers, both served by the Caddy proxy on PORT 8080. | An EC2 instance, EBS, an Elastic IP, and a load balancer to wire up. |
| Hetzner | Usage-based billing that tracks the RAM your index needs, and quick rollbacks from the dashboard. | Cheap RAM, but you own the reverse proxy, backups, and restarts after reboots. |

## Common Use Cases for hosted Typesense Rails

- **Product catalog search:** Include Typesense in the `Product` model and index names, descriptions and prices, so shoppers searching "blue running shoe" get ranked results in milliseconds. Typo tolerance catches the misspellings people make constantly.
- **Admin and back-office lookups:** Support staff can find a customer by email fragment or order number with `Customer.search(params[:q], 'name,email')`, without a pile of `LIKE` queries.
- **Help center and ActionText content:** Index `description.to_plain_text` so rich text bodies become searchable, and attach a synonym set on v30+ so "login" and "sign in" match each other.
- **Filtered listing pages:** Pass `filter_by: 'price:&lt; 500'` and `sort_by: 'price:asc'` into the model search to keep filtering logic in Ruby instead of hand-built SQL.
- **Frequently changing records:** Turn on `typesense enqueue: true` so writes go through ActiveJob, and run a nightly `Product.where('updated_at &gt; ?', 10.minutes.ago).reindex!` as a safety net for anything the callbacks missed.

## Dependencies for Typesense Rails Docker hosted on Railway

Before you touch the Gemfile, know what's running on the other end. You need network reach, a real admin key, and a volume that survives redeploys.

### Deployment Dependencies for Managed Typesense Rails Service (Search Engine for Rails Apps)

Caddy listens on PORT 8080 and forwards to Typesense on 127.0.0.1:8118, so the public HTTPS domain and the private URL both hit the proxy.

### Implementation Details for Typesense Rails (Using Typesense official docker image)

Add `gem 'typesense-rails', '~&gt; 1.0.0.rc1'` to the Gemfile and run `bundle install`. Skip that step and search returns nothing, which is a fun afternoon to lose.

## How does Typesense Rails compare against other search options for Rails apps platforms

Most Rails teams land on one question: a separate search server, or let the database do the work? Each option below wins somewhere.

### Typesense Rails vs Algolia Rails (Algolia Alternative)

- **Hosting model:** Algolia Rails calls a hosted SaaS API with nothing to run. Typesense Rails points the gem at a Railway service you control.
- **Cost shape:** Algolia bills per search request and per stored record. Self-hosted Typesense bills for compute and disk.
- **Where Algolia wins:** zero infrastructure and a global footprint without effort.

### Typesense Rails vs Elasticsearch Searchkick (Searchkick Alternative)

- **Operational weight:** Searchkick needs an Elasticsearch cluster and JVM tuning. Typesense Rails is one lightweight process with its data on a volume.
- **Relevance tuning:** Searchkick exposes the full Elasticsearch query DSL. Typesense Rails covers most catalog search with declared attributes, synonyms and curations.
- **Where Searchkick wins:** log analytics and heavy aggregations.

### Typesense Rails vs pg_search (pg_search Alternative)

- **No extra service:** pg_search uses PostgreSQL features, so there is no second server to secure or back up.
- **Typo tolerance:** Typesense Rails tolerates typos by default. pg_search is harder to tune for fuzzy matching.
- **Where pg_search wins:** small apps where search is a minor feature and data already lives in Postgres.

### Typesense Rails vs Meilisearch (Meilisearch Alternative)

- **Similar goal:** Meilisearch is also open source and built for instant, typo-tolerant search, so both suit a Rails app.
- **Typesense Rails specifics:** the typesense-rails gem wires `typesense do` blocks, scoped search keys and synonym sets straight into ActiveRecord models.
- **Where Meilisearch wins:** if your team already runs it, switching costs more than it gains.

## How to use Typesense Rails (the OSS Search Engine for Rails Apps)?

Once the Railway service is green, point your Rails app at it. This is the official gem, and it works with ActiveRecord, Sequel and Mongoid models.

Create `config/initializers/typesense.rb` with your Railway public domain on port 443 and protocol `https`, matching `TYPESENSE_PUBLIC_URL`. Keep the admin key in this file only.

Include Typesense in a model and declare what to index:

```ruby
class Product &lt; ApplicationRecord
  include Typesense
  typesense do
    attributes :name, :description, :price
  end
end
```

Reindex existing rows with `Product.reindex`, then test from the console with `Product.search('phone', 'name,description')`.

## How to self host Typesense Rails on other VPS Services (Typesense Rails self hosting guide)

Run the same Rails integration against a Typesense node you manage on a generic VPS.

### Clone the Repository

```
git clone https://github.com/Shinyduo/typesense-railway.git
cd typesense-railway
```

### Install Dependencies

Add the gem to your Gemfile, then install:

```
gem 'typesense-rails', '~&gt; 1.0.0.rc1'
```

```
bundle install
```

### Configure Environment Variables

Read connection details from ENV so no secret lands in git:

```ruby
# config/initializers/typesense.rb
Typesense.configuration = {
  nodes: [{ host: ENV.fetch('TYPESENSE_HOST', 'your-domain'), port: '443', protocol: 'https' }],
  api_key: ENV.fetch('TYPESENSE_API_KEY'),
  connection_timeout_seconds: 2,
  log_level: :info
}
```

Keep the admin key server-side. Browser code gets a scoped search key from the /keys API.

### Start the Typesense Rails Application

```
bin/rails runner 'Product.reindex!'
bin/rails server
```

Railway handles the node, TLS and volume for you, which is why its template skips the reverse proxy and data-directory wiring above.

## Official Pricing of Typesense Rails (Typesense Rails pricing)

Typesense Rails is free and open source, so the gem and the Typesense server carry no license fee and no per-search meter. Check its site for current rates.

## Typesense Rails cloud vs self hosted comparison (Pricing, features, costs, and more)

Typesense Rails runs the same gem whether the engine is Typesense Cloud or a node you run yourself, so the real choice is who handles upgrades and the bill.

### Monthly cost of self hosting Typesense Rails on Railway

On Railway you pay for the compute the Typesense service uses plus the volume that holds your index. A small node usually lands in the single digits to low teens of USD per month.

### System Requirements for Hosting Typesense Rails on a VPS

Typesense is in-memory, so size RAM to your largest collection plus headroom for indexing. Watch memory during a full Product.reindex, since that is where spikes happen.

## Frequently Asked Questions (FAQs)

### Do I need to set up a Typesense cluster before adding the gem?

Not really. The gem only needs a reachable node and a valid key.

### Where should the admin key live?

Keep TYPESENSE_API_KEY in the server-side initializer and never ship it to browser code.

### Why are my existing rows missing from search results?

Adding `include Typesense` only affects records written after the model is wired up.

### Does the Railway template enable CORS for browser clients?

No, CORS is not enabled by default in this template. If a browser app calls Typesense directly, you will need to configure CORS yourself or route requests through your Rails backend.

### Should I use synchronous or background indexing?

For small tables synchronous indexing is fine. Once writes get busy, turn on `typesense enqueue: true` so ActiveJob handles indexing and your request cycle stays quick.

### What if I deployed the template and never changed the API key?

Replace TYPESENSE_API_KEY with your own long random value right after deploy. The template default is public knowledge, so leaving it in place means anyone who finds it can read and write your indexes.


## Similar templates

- [Plausible WordPress](https://railway.com/deploy/deploy-plausible-for-wordpress-sites) — Cookie-free WordPress stats from your own Plausible
- [Typesense Multilingual](https://railway.com/deploy/deploy-typesense-multilingual-search) — Locale-aware multilingual search with Typesense
- [Formbricks](https://railway.com/deploy/formbricks-surveys) — Surveys, NPS and in-app feedback on your own Postgres, Hub and Cube

Open this page in a browser: https://railway.com/deploy/deploy-typesense-for-ruby-on-rails
