Skip to content

Shared services

Each workspace runs a separate copy of each service. Some services are heavy or slow to start, and they use nothing that is different in each workspace. For these services, you can run one shared instance. All workspaces that select it use that one instance. This guide tells how to share a service, how to see the instances, and how to remove one.

A shared instance serves more than one workspace. It must use nothing that is different in each workspace. The author of the template decides this, and marks the service in the template:

localspace.yaml
services:
customer:
repo: customer-service
port: 8080
shareable: true
env:
DATABASE_URL: ${customer-db.url}
Field Effect
shareable: true A workspace can share the service when you select it with --share.
shared: true A workspace shares the service by default. This value implies shareable: true.

lo new refuses to share a service in these cases:

  • The template does not mark the service shareable or shared.
  • The service has an environment value with a reference such as ${workspace.slug}, which is different in each workspace.
  • The service refers to a service that is not shared.
  • The service uses a resource or a volume that a different service uses too.

A resource that only the shared service uses belongs to the shared instance. For example, the database customer-db above is part of the shared instance of customer. The workspaces do not get a separate copy of it.

  1. Select the service when you make the workspace:

    Terminal window
    lo new shop-a --template shopping --share customer
  2. Run lo up shop-a. lo up also starts the shared instance.

  3. Run lo new shop-b --template shopping --share customer, then lo up shop-b. The workspace shop-b uses the same instance as shop-a.

The services of the workspace use the shared service with their usual references, for example ${customer.internal_url}. If the service is exposed, its public URL has the reserved workspace name shared, for example https://customer-main.shared.lo. The first part of the host name has the service and the ref.

An instance has a template, a service and a ref. The ref is the branch or commit of the source that the service runs. For a service with an image, the image is the ref. Workspaces of one template that use the same service at the same ref use one instance. A workspace with a different ref makes a different instance.

If the template marks a service shared: true, each new workspace uses the shared instance. To run a separate copy in one workspace, use one of these options:

  • Add --own <service> to lo new.
  • Name the service, or its repository, with a ref, for example lo new shop-c --template shopping customer=feature/x.

You cannot name the same service in --share and --own.

Run lo shared ls to list the instances. The table shows the instance as <service>@<ref>, its template, its status and the workspaces that use it.

Terminal window
lo shared ls

lo down stops the shared instances that no other running workspace uses. lo rm does the same. The instance and its data stay on the machine. The next lo up of a workspace that uses it starts it again.

To delete an instance, remove the workspaces that use it. Then run lo shared rm <service>@<ref>.

lo shared rm stops the instance and drops its resources. It refuses while a workspace uses the instance. It also refuses if the worktrees of the instance contain unsaved work.