Architecture and deployment topologies

Four roles, three databases, and one bus: how requests travel after Grape is deployed, and where to look first when something fails.

1. Three things to remember first

A deployed Grape is not one "big service". It is:

  1. Four processes: each owns one part of the business
  2. Three databases: each part of the business keeps its own data
  3. One bus: processes call each other through it when a call crosses domains

Start with a simplified diagram:

Browser / CLI
      │
      ▼
   nginx (frontend)
      │
      ├── daily pages, sign-in, configuration ─────► mgmt     (office area)
      ├── Git platform events, webhooks ───────────► event    (mailroom)
      ├── task execution, Worker ──────────────────► worker   (workshop)
      └── dashboards, logs, monitoring ────────────► insight  (monitoring room)

The four processes can run on one machine or be split across several. A single machine can run everything, but during troubleshooting you need to know which process a request lands on.

2. What the four processes do

Think of it as a company:

Process Think of it as Main responsibility Default port
mgmt Office area Sign-in, users, repositories, scenes, Skills, configuration, front-end pages 38080
event Mailroom Receives Git platform webhooks, turns events into tasks, A2A handoff 38081
worker Workshop Claims tasks, invokes the Agent engine, executes, reports results 38082
insight Monitoring room Dashboards, logs, metrics, SLOs, global search 38083

The deployment units are:

grape-server
grape-event-server
grape-worker-server
grape-insight-server

Health checks differ; do not query the wrong one during troubleshooting:

Process Health check
mgmt / insight GET /api/health
event / worker GET /health (only proves the process is alive; does not query the database)

Older scripts may use 38081–38084; the current nginx and systemd units use 38080–38083, which is authoritative.

3. How a request travels

Scenario 1: Open the console, sign in, change configuration

Browser → nginx → mgmt → grape_mgmt_db

mgmt owns the user-facing side and configuration. If pages do not load, sign-in fails, or repository, scene, or Skill settings do not take effect, check mgmt first.

Scenario 2: Someone creates an Issue on the Git platform

Git platform → nginx → event → grape_runtime_db
                         → create task
                         → worker claims it

event only "brings the event in and writes it as a task"; it does not execute anything. If a webhook does not fire, the event page has no record, or an A2A handoff fails, check event first.

Scenario 3: An Agent starts executing a task

worker → claim task → invoke the engine (opencode/hermes/codearts/...)
       → fetch repository/scene configuration from mgmt when needed
       → write results back to grape_runtime_db
       → report logs/metrics to insight

If tasks queue up, the engine is offline, an Agent fails halfway, or exit_code is abnormal, check worker and the engine health check.

Scenario 4: Read dashboards, search logs

Browser → nginx → insight → grape_insight_db / Loki / Prometheus

insight reads monitoring data and does not query business databases. If dashboards are empty or logs are missing, check insight and the collection path.

4. How the three databases are split

Database What it stores Who writes
grape_mgmt_db Accounts, repositories, scenes, Skills, credentials, management configuration mgmt
grape_runtime_db Tasks, events, sessions, messages, Workers, runtime credentials event (worker only reads and writes; it does not run migrations)
grape_insight_db Logs, metrics, SLOs, dashboard data insight

Why three databases? In short: each part of the business owns its own data, so the four processes never modify the same table at the same time.

Three rules apply in practice:

  1. Write only your own database: mgmt does not write the runtime database directly, and worker does not modify mgmt tables directly.
  2. Read across domains through views: tables from another domain are read-only views in the current database; if a migration adds a column, the view may still be old.
  3. Migrations have an order: migrate, then fix views, then re-check, and only then restart. The wrong order produces missing columns or error 1146.

Three-database mode starts from a DSN file referenced by GRAPE_3DB_ENV; the launcher then splits the matching database into DEVOPS_DB_* per process role. For day-to-day troubleshooting you only need to confirm one thing: is each process connected to its own database?

Common deployment environment variables

Variable Default Effect
DEVOPS_DB_NAME empty Explicitly sets the database name for this process; when empty it is inferred from the process role (the rest of DEVOPS_DB_* such as DEVOPS_DB_HOST / DEVOPS_DB_USER come from the same source)
GRAPE_AI_FILL_MAX_TOKENS 16000 Output cap for one AI-fill call (scene/Skill metadata suggestions)
GRAPE_AI_FILL_TIMEOUT_SECONDS 180 Timeout for an AI-fill call (seconds)

5. What GSB is

GSB is Grape's service bus. It handles three things:

  • Service registration: each process registers where it runs at startup
  • Service discovery: other processes can look it up when they need it
  • Remote calls: when a call crosses processes, it is issued according to configuration

The default is local calls

Most deployments default to Local: cross-domain reads go through views or public methods in the current database, without HTTP.

Remote is used only when remote mode is explicitly enabled:

GRAPE_PROVIDER_MODE=remote

Do not reason in terms of same machine vs. cross-machine

A common misconception:

Processes on the same machine use Local, and processes on different machines use Remote.

That is wrong. Local or Remote depends on deployment configuration and method routing, not on automatic IP detection. Processes on the same machine can be configured for Remote, and processes on different machines can use Local. Local is the default; Remote is an explicit mode.

Remote failures do not fall back silently

A Remote timeout or unreachable target reports an error directly (for example GSB_REMOTE_TIMEOUT) and does not switch to Local automatically. This prevents the same request from taking different data paths on different nodes.

When to care about GSB

Deployment topology Do you need to tune GSB
Four processes on one machine Usually not
Single machine plus remote Worker Usually not either
Multiple machines split by domain, cross-machine calls Yes: check service registration, routing, and timeouts

6. Common deployment topologies

Topology 1: Four processes on a single machine

One machine: nginx + mgmt + event + worker + insight
Databases: three databases (can be on the same machine)

Suited to trials, small teams, and single-machine self-hosting.

Topology 2: Single-machine services plus a remote Worker

Server: nginx + mgmt + event + insight
Worker machine: worker + engines

Suited to running tasks on dedicated machines and to setups with multiple execution machines.

Topology 3: Multiple machines split by domain

mgmt / event / worker / insight split across different machines

Suited to workloads with moderate concurrency that need independent scaling or isolation. This is when GSB registration, routing, and remote calls need real attention.

7. Upgrade order

The domain-split / multi-database MySQL mode cannot be restarted directly. The correct order:

Backup
  → Migrate
    → Fix views
      → Re-check
        → Restart

If any of the first three steps returns non-zero, do not restart. For the actual commands and rollback, see:

8. What counts as a successful deployment

Check Expected
Four processes All four systemd units active; ports 38080–38083 listening
Health checks mgmt/insight /api/health returns 200; event/worker /health returns 200
Databases Each process is connected to its own database
GSB registration All four services online, heartbeats not expired
Cross-domain reads Pages can read cross-domain data, with no missing columns or 1146
Task path Create an Issue; it reaches worker and produces logs

9. Where to look first when something fails

Symptom Likely cause First action
Pages do not load, sign-in fails mgmt or nginx Check the mgmt health check and nginx forwarding
Webhook returns 200 but no Pipeline event or repository configuration Check the event page, the webhook Secret, and event types
Tasks stay queued worker or engine Check Worker online status, engine health checks, and whether the scene is applied
A task fails midway engine or Worker Check node logs, exit_code, memory, and timeouts
No dashboard data insight or collection Check the insight health check and log/metric collection
Cross-domain pages show missing columns or 1146 views were not fixed after migration Run the post-migration fix script; do not restart directly
Only some of the four processes start port conflict or unit not enabled Check port usage and the systemd units

Database backends and official sync | Upgrade, backup, and rollback | Observability stack