Skip to content

Quick Start

Your first event

The simplest way to use Synkro is to define an event and publish a message to it.

In-memory

import { Synkro } from "@synkro/core";
const synkro = await Synkro.start({
transport: "in-memory",
events: [
{
type: "UserSignedUp",
handler: async (ctx) => {
console.log("New user:", ctx.payload);
},
},
],
});
await synkro.publish("UserSignedUp", { email: "user@example.com" });

Redis

Switch to Redis by changing two configuration fields. Everything else stays the same.

import { Synkro } from "@synkro/core";
const synkro = await Synkro.start({
transport: "redis",
connectionUrl: "redis://localhost:6379",
events: [
{
type: "UserSignedUp",
handler: async (ctx) => {
console.log("New user:", ctx.payload);
},
},
],
});
await synkro.publish("UserSignedUp", { email: "user@example.com" });

Your first workflow

Workflows chain multiple steps into a sequential pipeline. Each step runs in order, and state is persisted between steps.

import { Synkro } from "@synkro/core";
const synkro = await Synkro.start({
transport: "redis",
connectionUrl: "redis://localhost:6379",
workflows: [
{
name: "ProcessOrder",
steps: [
{
type: "ValidateStock",
handler: async (ctx) => {
console.log("Checking stock for order:", ctx.requestId);
},
},
{
type: "ProcessPayment",
handler: async (ctx) => {
console.log("Processing payment...");
},
},
{
type: "SendConfirmation",
handler: async (ctx) => {
console.log("Order confirmed!");
},
},
],
},
],
});
await synkro.publish("ProcessOrder", { orderId: "abc-123", amount: 49.99 });

When you publish "ProcessOrder", Synkro executes ValidateStock, then ProcessPayment, then SendConfirmation in sequence. If any step fails, the workflow status is set to failed and subsequent steps are skipped.

Add a dashboard

The @synkro/ui package provides a web dashboard you can mount on any Node.js HTTP server.

  1. Install the UI package

    Terminal window
    npm install @synkro/ui
  2. Create the handler and mount it with Express

    import express from "express";
    import { Synkro } from "@synkro/core";
    import { createDashboardHandler } from "@synkro/ui";
    const synkro = await Synkro.start({
    transport: "redis",
    connectionUrl: "redis://localhost:6379",
    events: [
    {
    type: "UserSignedUp",
    handler: async (ctx) => {
    console.log("New user:", ctx.payload);
    },
    },
    ],
    });
    const app = express();
    // Mount the dashboard at /dashboard
    app.use("/dashboard", createDashboardHandler(synkro, { basePath: "/dashboard" }));
    app.listen(3000, () => {
    console.log("Dashboard available at http://localhost:3000/dashboard");
    });
  3. Open the dashboard

    Navigate to http://localhost:3000/dashboard in your browser to see your registered events, workflows, and metrics.

Next steps

Now that you have events, workflows, and a dashboard running, explore the core concepts to understand what is happening under the hood.