Skip to content

Quick Start

Get a Strata service running in 5 minutes.

Prerequisites

  • Node.js v18 or later
  • A running Redis instance (default: localhost:6379)

If you don't have Redis running locally, the fastest way to get it going:

bash
# Docker
docker run -d -p 6379:6379 redis

# macOS
brew install redis && brew services start redis

Install

Create a new project and install Strata:

bash
mkdir my-service && cd my-service
npm init -y
npm install @strata-js/strata

Create a Service

Create service.ts with a single context and one operation:

typescript
import { StrataService, Context } from '@strata-js/strata';

// Create the service
const service = new StrataService({
    service: { serviceGroup: 'QuickStart' },
    backend: { type: 'redis', redis: { host: 'localhost', port: 6379 } },
});

// Create a context with an echo operation
const echo = new Context('echo');

echo.registerOperation('send', async (request) =>
{
    return { message: `You said: ${ request.payload.text }` };
});

// Register the context and start
service.registerContext(echo);
await service.start();

That's all the service needs. It listens on the QuickStart service group, routes requests to the echo context, and the send operation returns whatever text you give it.

Create a Client

In a separate file, create client.ts:

typescript
import { StrataClient } from '@strata-js/strata';

const client = new StrataClient({
    client: { name: 'QuickStartClient' },
    backend: { type: 'redis', redis: { host: 'localhost', port: 6379 } },
});

await client.start();

// Send a request to the service
const response = await client.request('QuickStart', 'echo', 'send', {
    text: 'Hello, Strata!',
});

console.log(response.payload);
// { message: 'You said: Hello, Strata!' }

process.exit(0);

The client connects to the same Redis backend, sends a request to the QuickStart service group targeting the echo context and send operation, and prints the response payload.

Run It

Start the service in one terminal:

bash
npx tsx service.ts

Send a request from another:

bash
npx tsx client.ts

You should see { message: 'You said: Hello, Strata!' } printed in the client terminal.

What Just Happened

  1. The service connected to Redis and started listening on the Requests:QuickStart queue.
  2. The client pushed a request envelope onto that queue with context echo and operation send.
  3. The service popped the message, routed it to the echo context's send handler, and pushed the response back to the client's dedicated response queue.
  4. The client received the response and printed the payload.

All of the envelope construction, queue management, routing, and response matching happened automatically. You wrote a handler function and a request call -- Strata handled the rest.

Next Steps

  • Your First Service -- build a more realistic service with multiple contexts, middleware, configuration files, and service-to-service calls.
  • Configuration -- understand every option in the service and client config.
  • Architecture -- how services, contexts, and operations fit together.