Connecting services within your project

Connecting services within your project #

More often than not, our applications require multiple services to communicate with each other. Being secure by design, levv does not allow trafic to flow between services by default.

In this guide, we will go through the most important steps to configure communication between services, based on the sample storage app available at this Gitlab repository.

The sample application is a simple Go app that provides data storage functionality through HTTP requests. It uses two external services: MySQL for persistence and valkey as a temporary cache.

Exposing services #

In order to access these services, the compose specification requires at least one ports entry that specifies the corresponding service-port:container-port value.

For example, in the case of the cache service, port 6379 in the container is published as a service on the same port:

services:
    cache:
        image: valkey/valkey
        ports:
            - 6379:6379
[...]

Something similar can be observed for the db service:

db:
    image: mysql
    ports:
        - 3306:3306

Defining ports will make the service reachable from other containers within the same project. Without defining ports, your services will not be reachable.

Accessing exposed services #

When you create a service exposing ports, it is possible to access it from any other application using its name, but only within the same project. No Fully Qualified Domain Name (FQDN) is needed, as levv cloud will internally resolve the correspondig addresses.

Exposing services will not make your application available publicly, it will only expose ports inside of the project.

In this case, our sample app requires an environment variable named KV_ADDR where we must specify the address to connect the cache service and a MYSQL_ADDR for the database.

storage-app:
    image: levvio/apps:sample-storage
    environment:
      MYSQL_ADDR: "db:3306"
      KV_ADDR: "cache:6379"
    [...]

Other applications might not require that you specify the service port.

Please refer to the full compose specification for all the configuration details, and the Readme for launching this app on your levv cloud project.


As you have seen, levv simplifies inter-service communication, ensuring secure and efficient connectivity within your projects.