How Spica runs
The processes and services that make up a Spica deployment, what each one is responsible for and how requests travel between them.
A Spica deployment is a small set of services. Understanding them makes it easier to run Spica locally, size it for production and debug it.
The pieces
| Component | Image | Responsibility |
|---|---|---|
| API | spicaengine/api | Every module: buckets, functions, passport, storage, dashboards, webhooks, activity, config and status. Listens on one HTTP port and, for gRPC triggers, on port 50051. |
| Panel | spicaengine/panel | The admin panel, a static web app served by nginx. It calls the API at /api on the same origin. |
| Database | mongo or spicaengine/postgres | Stores everything. MongoDB must run as a replica set because Spica relies on change streams. |
| Ingress | nginx or your Kubernetes ingress | Routes / to the panel and /api to the API, and terminates TLS. |
| Function workers | Child processes of the API | Run your function code in isolated Node.js processes. |
| Object storage | Local disk, S3 or GCS | Holds uploaded files when you use the storage module. |
Request path
Clients only talk to the ingress. A typical production setup serves the panel and the API from the same host:
https://admin.example.com/ → panel
https://admin.example.com/api/ → API (the --public-url of the API)The API's --public-url must be the URL that clients use to reach it, including the /api suffix when you serve it under a path. Spica uses it to build storage object URLs, OAuth redirect URLs and magic links.
Function workers
The API schedules function events onto workers: Node.js processes that load your function's code and run the handler that matches the trigger.
- Each function gets its own workers, so a crashing or slow function doesn't affect others.
- Workers are started on demand. A function can keep some workers warm to skip the cold start.
- A worker can run several events of the same function at once when you raise the function's
concurrencyPerWorker. - Every event has a timeout. When it is reached, the event is aborted.
See Runtime and scaling for the settings that control workers.
Realtime and change streams
Realtime bucket streams, bucket triggers, database triggers and webhooks are all driven by database change events. On MongoDB they come from change streams, which is why MongoDB has to run as a replica set, even with a single node.
Running more than one API replica
You can run several API replicas behind a load balancer. Turn on --replication so that the replicas coordinate work, and make sure every replica can reach the same function assets and storage files. Use a shared volume or the S3/GCS strategies. The Helm chart does this for you when application.replicas is greater than one.
Where data lives
| Data | Location |
|---|---|
| Buckets, documents, identities, users, policies, functions, logs | The database |
| Function source and installed packages | --persistent-path or the function asset storage (local path, S3 or GCS) |
| Uploaded files | --persistent-path/storage, S3 or GCS |
| Logs, activity and status records | The database, expired after --common-log-lifespan |