SearchFn
Operations

Setup

Deploy SearchFn in production with proper configuration, limits, and resilience.

Deployment Steps

  1. Choose an adapter — pick the adapter that matches your infrastructure. See Adapters for a comparison.
  2. Run backend infrastructure — set up Postgres, Meilisearch, or Elasticsearch/OpenSearch if using a server-side adapter.
  3. Run migrations — for PostgresAdapter, execute the migration SQL to create required tables and indexes.
  4. Initialize resources — call initialize() with your resource definitions before indexing traffic.
  5. Create the server — use createSearchFnServer() to expose search over HTTP.
  6. Mount the router — attach the server router to your HTTP framework using a @superfunctions/http adapter.
import { createSearchFnServer } from "@searchfn/server";
import { PostgresAdapter } from "@searchfn/adapters";

const server = await createSearchFnServer({
  adapter: new PostgresAdapter({
    connectionString: process.env.SEARCH_DB_URL!,
  }),
  basePath: "/searchfn",
});

// Mount server.router with Express, Fastify, Hono, etc.

Default Limits

The server enforces these limits by default. Override them in the limits configuration:

LimitDefaultDescription
maxQueryLength1,000Maximum search query string length.
maxLimit10,000Maximum limit parameter value.
maxLimitPerResource1,000Maximum limitPerResource parameter value.
maxResourcesPerSearchAll50Maximum resources in a searchAll request.
maxIndexBatch10,000Maximum documents per index request.
maxPayloadBytes1,048,576Maximum request body size (1 MB).
const server = await createSearchFnServer({
  adapter,
  limits: {
    maxQueryLength: 500,
    maxIndexBatch: 5000,
  },
});

Resilience

For external adapters (Postgres, Meilisearch, Elasticsearch/OpenSearch), configure timeouts and retries to handle transient failures:

const adapter = new PostgresAdapter({
  connectionString: process.env.SEARCH_DB_URL!,
  queryTimeoutMs: 15000,
  retry: {
    maxRetries: 3,
    baseDelayMs: 200,
    maxDelayMs: 10000,
  },
});
  • Use conservative timeouts that match your SLA requirements.
  • Bounded retries with exponential backoff and jitter prevent thundering herd problems.
  • Monitor retry rates to detect degraded backends early.

Environment Variables

Keep all credentials in environment variables or a secret store:

VariableUsed byDescription
SEARCH_DB_URLPostgresAdapterPostgres connection string
MEILI_URLMeilisearchAdapterMeilisearch endpoint
MEILI_API_KEYMeilisearchAdapterMeilisearch API key
ES_NODEElasticsearchAdapterElasticsearch/OpenSearch endpoint
ES_API_KEYElasticsearchAdapterElasticsearch API key