Skip to content

Your first event, end to end

This tutorial takes one event the whole way: your application writes it, the platform stores it, matches it to a subscription, and delivers it, signed, to an HTTP endpoint you run. By the end you will have used each of the pieces an application normally touches:

  • an application and its service account (the credentials your code uses);
  • definition sync: an event type, a connection and a subscription declared in code;
  • the transactional outbox and the fcdev outbox relay;
  • a webhook receiver that verifies the delivery’s signature;
  • the console’s events and dispatch jobs pages.

It takes about twenty minutes. Pick your language in any code tab; the choice carries through the page (and the rest of the site).

sequenceDiagram
  participant App as Your app
  participant DB as App database
  participant Relay as fcdev outbox
  participant FC as Platform (fcdev)
  participant Hook as Your webhook receiver
  App->>FC: definition sync (event type, connection, subscription)
  App->>DB: one transaction: business change + outbox row
  Relay->>DB: claim pending rows
  Relay->>FC: POST /api/events/batch
  FC->>FC: store event, match subscription, create dispatch job
  FC->>Hook: POST, signed with the connection's service account
  Hook-->>FC: 200
  • fcdev installed and running: Install and run fcdev.

  • A PostgreSQL database for your application. If you have none to hand, create one on fcdev’s embedded server (it is deleted if you ever reset the embedded database):

    Terminal window
    psql "postgresql://postgres:postgres@localhost:15432/flowcatalyst" -c 'CREATE DATABASE orders'
  • The SDK for your language:

Terminal window
go get github.com/flowcatalyst/go-sdk@v0.7.0

Go 1.27 or later. The module is served by the Go module proxy.

In your project directory, run:

Terminal window
fcdev init --code orders --name "Orders"

fcdev init connects to the running fcdev database and:

  • creates the Orders application (code orders);
  • reuses or creates a Default Client (identifier default) and prints its id;
  • provisions the application’s service account, code app:orders, named “Orders Service Account”, with the platform:application-service role, confined to this one application;
  • creates a confidential OAuth client for it (the client_credentials grant);
  • writes the credentials into ./.env:
Terminal window
FLOWCATALYST_BASE_URL=http://localhost:8080
FLOWCATALYST_APP_CODE=orders
FLOWCATALYST_CLIENT_ID=...
FLOWCATALYST_CLIENT_SECRET=...
FLOWCATALYST_SIGNING_SECRET=...
FLOWCATALYST_WEBHOOK_AUTH_TOKEN=...
FLOWCATALYST_APP_KEY=...

The client secret is shown only here: the platform keeps a hash. The signing secret and the webhook auth token are the service account’s delivery credentials (see the next step). Keep .env out of version control. If fcdev init asks for an administrator, the database has no anchor user yet; fcdev normally creates one on start, so check that fcdev is running.

Two rules come with these credentials, and the rest of the tutorial follows them:

  • every event type the application publishes must start with orders:; anything else is refused with 400, because it belongs to another application;
  • event types are registered through definition sync, not the general event-type admin API, which this role cannot use.

See applications and integrations and principals for what was just created.

2. Check the signing secret and set the database URL

Section titled “2. Check the signing secret and set the database URL”

Every delivery is signed with the signing secret of a service account; for this tutorial, the application’s own (see who signs a delivery). fcdev init already wrote it to .env as FLOWCATALYST_SIGNING_SECRET, with the bearer token the platform sends beside it as FLOWCATALYST_WEBHOOK_AUTH_TOKEN. Open .env and check that the signing secret is there. The receiver in the next step reads it from there.

Then add your application database’s URL to .env:

Terminal window
FC_OUTBOX_SOURCE_DB_URL=postgresql://postgres:postgres@localhost:15432/orders?sslmode=disable

The platform shows a signing secret only when it creates or regenerates it, so if you ran fcdev init earlier and .env has no FLOWCATALYST_SIGNING_SECRET (an application that already existed, or an .env you replaced), run it again for the same code with the regenerate flag:

Terminal window
fcdev init --code orders --regenerate-signing-secret

This replaces the service account’s signing secret and writes the new one to .env. A running copy of the application that verifies with the old secret refuses every delivery until it restarts with the new one. You can also regenerate it in the console (Service accounts, Orders Service Account, Signing Secret (HMAC-SHA256), Regenerate Secret; the value is shown once), or with POST /api/service-accounts/{id}/regenerate-signing-secret, which answers { "id", "signingSecret" }.

The receiver is the consumer: an HTTP endpoint that verifies the signature over the raw request body before it trusts anything, then answers 200. It must read the body as bytes; parsing and re-serialising JSON changes the bytes and breaks the signature.

package main
import (
"io"
"log"
"net/http"
"os"
"github.com/flowcatalyst/go-sdk/webhook"
)
func main() {
verifier := webhook.NewVerifier(os.Getenv("FLOWCATALYST_SIGNING_SECRET"))
http.HandleFunc("POST /webhooks/orders", func(w http.ResponseWriter, r *http.Request) {
body, err := io.ReadAll(r.Body) // the raw bytes, before any parsing
if err != nil {
http.Error(w, "read body", http.StatusBadRequest)
return
}
if err := verifier.Verify(body,
r.Header.Get(webhook.SignatureHeader),
r.Header.Get(webhook.TimestampHeader)); err != nil {
http.Error(w, "invalid signature", http.StatusUnauthorized)
return
}
log.Printf("job %s (%s): %s", r.Header.Get("X-Dispatch-Job-Id"), r.Header.Get("X-Event-Type"), body)
w.WriteHeader(http.StatusOK)
})
log.Fatal(http.ListenAndServe(":3000", nil))
}

Start it with FLOWCATALYST_SIGNING_SECRET in its environment (or loaded from .env). fcdev allows deliveries to localhost; a deployed platform does not, so there the endpoint must be reachable on a real address.

4. Declare the event type, connection and subscription

Section titled “4. Declare the event type, connection and subscription”

An application declares what it owns in code and syncs it: the platform makes its rows match. This set has three things:

  • the event type orders:sales:order:placed;
  • a connection orders-webhooks, owned by the application (its service account signs);
  • a subscription order-placed-local that sends orders:sales:order:placed events to your receiver, through that connection.

Run the sync once now. In a real application it runs on each deploy.

package main
import (
"context"
"log"
"os"
"github.com/flowcatalyst/go-sdk/auth"
"github.com/flowcatalyst/go-sdk/client"
"github.com/flowcatalyst/go-sdk/sync"
)
func main() {
base := os.Getenv("FLOWCATALYST_BASE_URL")
cc := auth.NewClientCredentialsProvider(auth.ClientCredentialsConfig{
IssuerURL: base,
ClientID: os.Getenv("FLOWCATALYST_CLIENT_ID"),
ClientSecret: os.Getenv("FLOWCATALYST_CLIENT_SECRET"),
})
c := client.New(base, client.WithTokenProvider(cc.Token))
set := sync.ForApplication("orders").
AddEventType(sync.MakeEventType("orders:sales:order:placed", "Order placed")).
AddConnection(sync.MakeConnection("orders-webhooks", "Orders webhooks")).
AddSubscription(sync.MakeSubscription("order-placed-local", "Order placed (local)",
"http://localhost:3000/webhooks/orders").
WithConnectionCode("orders-webhooks").
Bind("orders:sales:order:placed", ""))
res := sync.NewSynchronizer(c).Sync(context.Background(), set, sync.DefaultOptions())
if res.HasErrors() {
log.Fatal(res.Errors())
}
log.Println("synced")
}

Sync runs one call per category in dependency order (event types, then connections, then subscriptions), so the subscription can name a connection created in the same run. Every application-owned connection is signed by the application’s service account, the one whose secret is in your .env from step 2. In the console, Event types, Connections and Subscriptions now show the three rows, marked as coming from code. More on this in Declare definitions in code.

Your application does not call the platform to publish. It writes the event as a row in an outbox_messages table in its own database, in the same transaction as the business change, so the event exists if and only if the change committed. See the transactional outbox for why.

Create the table once. fcdev outbox create-table reads FC_OUTBOX_SOURCE_DB_URL from ./.env:

Terminal window
fcdev outbox create-table

(Each SDK also ships the same table as a migration; both produce the same schema.) Then write the event:

In Go the event is written by a use case: one business operation that returns a plan, which usecaseop.Run applies in one transaction (the order row and the event row together). examples/order-service in the SDK is the complete, runnable version of this sketch.

// The event: usecase.DomainEvent, usually by embedding usecase.EventMetadata.
type OrderPlaced struct {
Meta usecase.EventMetadata
OrderID string `json:"orderId"`
}
func (e OrderPlaced) EventID() string { return e.Meta.EventID }
func (e OrderPlaced) EventType() string { return e.Meta.Type }
// ... SpecVersion, Source, Subject, Time, PrincipalID, CorrelationID,
// CausationID, ExecutionID and MessageGroup delegate to Meta the same way.
func (e OrderPlaced) ToDataJSON() ([]byte, error) {
return json.Marshal(map[string]string{"orderId": e.OrderID})
}
func PlaceOrder(repo OrderRepository) usecaseop.Operation[PlaceOrderCommand, OrderPlaced] {
return usecaseop.Operation[PlaceOrderCommand, OrderPlaced]{
Name: "PlaceOrder",
Validate: func(context.Context, PlaceOrderCommand) error { return nil },
Authorize: usecaseop.Public[PlaceOrderCommand],
Execute: func(_ context.Context, cmd PlaceOrderCommand, ec usecase.ExecutionContext) (usecaseop.Plan[OrderPlaced], error) {
order := &Order{ID: tsid.GenerateWithPrefix("ord")}
meta := usecase.NewEventMetadata(ec, "orders:sales:order:placed", "orders:sales",
usecase.BuildSubject("sales", "order", order.ID))
meta.MessageGroup = usecase.BuildMessageGroup("sales", "order", order.ID)
return usecaseop.Save(order, repo, OrderPlaced{Meta: meta, OrderID: order.ID}), nil
},
}
}
// wiring: the pgx sink writes outbox_messages rows on the use case's transaction
sink := outboxpgx.NewSink(outboxpgx.Config{ApplicationCode: "orders"})
uow := usecasepgx.New(pool, sink)
event, err := usecaseop.Run(ctx, uow, PlaceOrder(repo), PlaceOrderCommand{},
usecase.NewExecutionContext("tutorial"))

The second argument of the outbox manager in Java, TypeScript and Rust is the value of the row’s client_id column: use the default client’s id that fcdev init printed. It labels the row in your table and is not sent with the event. The message group is the ordering key: events of one group are delivered in order (ordering).

The row now waits in your table. Nothing has reached the platform yet.

fcdev outbox is the relay that drains your table. It reads ./.env, connects to FC_OUTBOX_SOURCE_DB_URL, mints a token with FLOWCATALYST_CLIENT_ID and FLOWCATALYST_CLIENT_SECRET, and posts to http://localhost:8080 (override with FC_OUTBOX_PLATFORM_URL). In a new terminal, in the project directory:

Terminal window
fcdev outbox

It logs auth=client_credentials when it starts, then claims the pending row, posts it to POST /api/events/batch, and deletes it once the platform accepts it. Leave it running: it is what your application runs beside itself, in development and in production. Run one relay per outbox table.

Within a second or two your receiver logs the delivery. The body is the JSON envelope (the default for a new subscription):

{
"attemptNumber": 1,
"data": { "orderId": "ord_..." },
"id": "<dispatch job id>",
"messageGroup": "sales:order:ord_...",
"source": "orders:sales",
"time": "2026-11-10T09:15:02.481Z",
"type": "orders:sales:order:placed"
}

(plus dataContentType, subject, correlationId, clientId and clientCode when the job has them), with the headers X-Dispatch-Job-Id, X-Event-Type, X-FlowCatalyst-Timestamp, X-FlowCatalyst-Signature and Authorization: Bearer .... Answering 200 completes the job. What other answers do (ack: false to defer, 429, 5xx for a retry) is in delivery.

Then look in the console:

  • Events (/ui/events): the stored event, with its type, source, message group and data.
  • Dispatch jobs (/ui/dispatch-jobs): one job for the subscription, COMPLETED, with the attempt, its status code and timing. The list shows a recent time window; widen it to see older jobs.
Symptom Likely cause
The relay logs an error for the row The event type does not start with orders: (refused, and the row blocks its group), or the credentials in .env are wrong.
The event is in the console but there is no dispatch job The event type or the subscription is missing, or the subscription is paused. Check the sync’s result.
The job is FAILED with a connection error The receiver is not running, or listens on another port or path than the subscription’s target.
The job is FAILED with 401 The receiver refused the signature: FLOWCATALYST_SIGNING_SECRET is not the secret in .env from step 2 (regenerating it replaces it, so restart the receiver afterwards).
The job stays PENDING The connection is paused, or fcdev was started with the router or dispatch scheduler off.

A failed job is kept, with every attempt, until you act on it: fix the cause and use Requeue on the job’s page.

  • Code owns the definitions. The event type, connection and subscription live in your code and are synced on deploy; codes, not ids, make the same definitions work in every environment.
  • The outbox makes publishing atomic with your data, and the relay delivers at least once (with deduplication on the platform side).
  • Each subscription gets its own dispatch job, with retries, ordering per message group, and an audit trail of attempts.
  • The consumer trusts nothing it has not verified: the signature binds the secret, the time and the exact bytes.