Skip to content

Repository files navigation

Reference checkout microservice: Go, Restate, and Kafka

This repository is a working, local-first reference microservice for Go developers who are new to Restate. It models a checkout flow with durable orchestration, keyed state, compensation, event ingestion, service discovery, versioned contracts, and layered tests. AWS Lambda packaging is included, but an AWS account is not required for development.

Architecture at a glance

Component Restate type Responsibility
OrderWorkflow Workflow Runs checkout exactly once per order ID
Inventory Virtual Object Serializes stock changes per SKU
Payment Virtual Object Makes charge/refund idempotent per order
OrderEvents Virtual Object Consumes ordered Kafka events per order key
Notification Basic Service Demonstrates a replay-safe external side effect

Redpanda supplies a single-node, Kafka-compatible local broker. Restate consumes orders.submitted.v1 directly and invokes OrderEvents/OnOrderSubmitted; there is no handwritten consumer loop or offset management. See the architecture guide for the full request and event paths.

Prerequisites

  • Go 1.25 or newer
  • Docker Desktop or another Docker-compatible runtime
  • curl
  • Optional for AWS only: AWS CLI and AWS SAM CLI

The Restate CLI is useful for exploration but is not required: the repository's local-setup command uses the Restate Admin API directly.

Run the complete system locally

Start Restate and Redpanda:

make infra-up

Start the Go endpoint in a second terminal:

make run

Discover the Go services, create the Kafka topic, and install the event subscription from a third terminal:

make setup-local

The setup is idempotent and safe to repeat during local development.

Try the synchronous HTTP path

curl localhost:8080/Inventory/coffee-beans/Seed \
  --json '{"quantity":10}'

curl localhost:8080/OrderWorkflow/order-http-1001/Run \
  --json '{
    "customerId":"customer-42",
    "sku":"coffee-beans",
    "quantity":2,
    "amountCents":2400
  }'

Try the event-driven Kafka path

The example event uses order-1001 as both its Kafka key and event subject:

make publish-event

Kafka delivery is asynchronous. Inspect its durable receipt and workflow:

curl localhost:8080/OrderEvents/order-1001/Get
curl localhost:8080/OrderWorkflow/order-1001/Status

Open http://localhost:9070 to inspect discovered services, journals, invocations, state, retries, and the Kafka subscription. Stop the infrastructure with make infra-down.

Tests

make test              # formatting, vet, unit, and contract tests
make test-contract     # strict order-submitted contract tests only
make test-integration  # starts local infrastructure and tests HTTP + Kafka paths

The integration suite requires Docker but no cloud credentials. It builds the service into a temporary directory, registers it, creates the subscription, uses unique order/SKU keys, and verifies state through Restate ingress. See the testing strategy.

Repository map

cmd/
  local/              Local endpoint containing every service
  local-setup/        Idempotent discovery and subscription bootstrap
  event-publisher/    Standard-library Redpanda/Kafka REST producer
  *-lambda/           AWS Lambda entrypoints
config/               Local Restate Kafka configuration
contracts/            Versioned JSON Schema and example events
exercises/            Gamified developer onboarding track
internal/
  contracts/          Strict boundary validation
  domain/             Requests, events, responses, and status types
  eventing/            Replaceable local publisher adapter
  inventory/           Stateful stock virtual object
  order/               Durable checkout workflow and notification service
  orderevents/         Kafka-triggered order virtual object
  payment/             Idempotent payment virtual object
  restateadmin/        Small Admin API client for local discovery
test/integration/      Full-stack HTTP and Kafka tests
docs/                  Architecture, discovery, testing, and AWS guides

Onboarding path

Start at exercises/README.md. The course assumes strong Go skills and teaches Restate by asking developers to collect points and badges for observable behaviors: per-key serialization, durable replay, idempotency, contract enforcement, event delivery, compensation, and discovery.

AWS path

The same service implementations are bound to independent Lambda entrypoints. Restate invokes versioned Lambda functions directly; API Gateway is not required between Restate and a service handler. See docs/aws-deployment.md. The local Redpanda broker can later be replaced by Amazon MSK or Confluent Cloud; the event contract and Restate handler remain unchanged.

Further reading

About

A demo repository for learing and tinkering with Restate.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages