> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Relationships

> A dictionary of relationships that defines the connections to other services and apps.

Optional in [single-runtime](https://developer.upsun.com/docs/configure-apps/app-reference/single-runtime-image.md#primary-application-properties) and [composable](https://developer.upsun.com/docs/configure-apps/app-reference/composable-image.md#primary-application-properties) images.

To allow containers in your project to communicate with one another,
you need to define relationships between them.
You can define a relationship between an app and a service, or [between two apps](https://developer.upsun.com/docs/configure-apps/multi-app/relationships.md).

The quickest way to define a relationship between your app and a service
is to use the service's default endpoint.\

However, some services allow you to define multiple databases, cores, and/or permissions.
In these cases, you can't rely on default endpoints.
Instead, you can explicitly define multiple endpoints when setting up your relationships.

> [!NOTE]
>
> App containers don't have a default endpoint like services.
> To connect your app to another app in your project,
> you need to explicitly define the `http` endpoint as the endpoint to connect both apps.\\
>
> For more information, see how to [define relationships between your apps](https://developer.upsun.com/docs/configure-apps/multi-app/relationships.md).

> [!NOTE]
>
> Availability
> New syntax (default and explicit endpoints) described below is supported by most, but not all, image types
> (`Relationship 'SERVICE_NAME' of application 'app' ... targets a service without a valid default endpoint configuration.`).
> This syntax is currently being rolled out for all images.
> If you encounter this error, use the "legacy" Upsun Cloud configuration noted at the bottom of this section.

To define a relationship between your app and a service:

> [tab] Using default endpoints
>
> Use the following configuration:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             \<SERVICE\_NAME>:
>
> The `SERVICE_NAME` is the name of the service as defined in its [configuration](https://developer.upsun.com/docs/add-services).
> It is used as the relationship name, and associated with a `null` value.
> This instructs Upsun Cloud to use the service's default endpoint to connect your app to the service.
>
> For example, if you define the following configuration:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             mariadb:
>
> Upsun Cloud looks for a service named `mariadb` in your `.upsun/config.yaml` file,
> and connects your app to it through the service's default endpoint.
>
> For reference, the equivalent configuration using explicit endpoints would be the following:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             mariadb:
> &#x20;               service: mariadb
> &#x20;               endpoint: mysql
>
> You can define any number of relationships in this way:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             mariadb:
> &#x20;             redis:
> &#x20;             elasticsearch:
>
> > [!NOTE]
> >
> > Tip
> > An even quicker way to define many relationships is to use the following single-line configuration:
> >
> > &#x20;         applications:
> > &#x20;           \<APP\_NAME>:
> > &#x20;             \# ...
> > &#x20;             relationships:&#x20;
> > &#x20;               \<SERVICE\_NAME\_A>
> > &#x20;               \<SERVICE\_NAME\_B>
> > &#x20;               \<SERVICE\_NAME\_C>
> >
> > &#x20;         services:
> > &#x20;           \<SERVICE\_NAME\_A>:
> > &#x20;             type: mariadb:\{\{version:mariadb:latest}}
> > &#x20;           \<SERVICE\_NAME\_B>:
> > &#x20;             type: redis:\{\{version:redis:latest}}
> > &#x20;           \<SERVICE\_NAME\_C>:
> > &#x20;             type: elasticsearch:\{\{version:elasticsearch:latest}}

> [tab] Using explicit endpoints
>
> Use the following configuration:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             \<RELATIONSHIP\_NAME>:
> &#x20;               service: \<SERVICE\_NAME>
> &#x20;               endpoint: \<ENDPOINT\_NAME>
>
> * `RELATIONSHIP_NAME` is the name you want to give to the relationship.
> * `SERVICE_NAME` is the name of the service as defined in its [configuration](https://developer.upsun.com/docs/add-services).
> * `ENDPOINT_NAME` is the endpoint your app will use to connect to the service (refer to the service reference to know which value to use).
>
> For example, to define a relationship named `database` that connects your app to a service called `mariadb` through the `db1` endpoint,
> use the following configuration:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             database: # The name of the relationship.
> &#x20;               service: mariadb
> &#x20;               endpoint: db1
>
> For more information on how to handle multiple databases, multiple cores,
> and/or different permissions with services that support such features,
> see each service's dedicated page:
>
> * [MariaDB/MySQL](https://developer.upsun.com/docs/add-services/mysql#multiple-databases) (multiple databases and permissions)
> * [PostgreSQL](https://developer.upsun.com/docs/add-services/postgresql#multiple-databases) (multiple databases and permissions)
> * [Redis](https://developer.upsun.com/docs/add-services/redis.md#multiple-databases) (multiple databases)
> * [Solr](https://developer.upsun.com/docs/add-services/solr.md#solr-6-and-later) (multiple cores)
> * [Vault KMS](https://developer.upsun.com/docs/add-services/vault.md#multiple-endpoints-example) (multiple permissions)
>
> You can add as many relationships as you want to your app configuration,
> using both default and explicit endpoints according to your needs:
>
> &#x20;       applications:
> &#x20;         \<APP\_NAME>:
> &#x20;           \# ...
> &#x20;           relationships:
> &#x20;             database1:
> &#x20;               service: mariadb
> &#x20;               endpoint: admin
> &#x20;             database2:
> &#x20;               service: mariadb
> &#x20;               endpoint: legacy
> &#x20;             cache:
> &#x20;               service: redis
> &#x20;             search:
> &#x20;               service: elasticsearch

> [!NOTE]
>
> Legacy
> The following legacy syntax for specifying relationships is still supported by Upsun Cloud:
>
> &#x20;     applications:
> &#x20;       \<APP\_NAME>:
> &#x20;         \# ...
> &#x20;         relationships:
> &#x20;           \<RELATIONSHIP\_NAME>: "\<SERVICE\_NAME>:\<ENDPOINT\_NAME>"
>
> &#x20;     services:
> &#x20;       SERVICE\_NAME\_A:
> &#x20;         type: mariadb:\{\{version:mariadb:latest}}
>
> For example:
>
> &#x20;     applications:
> &#x20;       \<APP\_NAME>:
> &#x20;         \# ...
> &#x20;         relationships:
> &#x20;           database: "db:mysql"
>
> &#x20;     services:
> &#x20;       db:
> &#x20;         type: mariadb:\{\{version:mariadb:latest}}
>
> Feel free to use this until the default and explicit endpoint syntax is supported on all images.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.