How To: Service to service networking

Learn how your Radius services can communicate with each other

This guide will show you how two services can communicate with each other. In this example, we will have a frontend container service that communicates with a backend container service.

Prerequisites

Step 1: Define the services

First, define the containers in a file named app.bicep. We will define two services: frontend and backend:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import radius as rad

@description('The application ID of the Radius environment. Automatically set by the rad CLI.')
param application string

resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'frontend'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
      ports: {
        web: {
          containerPort: 3000
        }
      }
    }
  }
}

resource backend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'backend'
  properties: {
    application: application
    container: {
      image: 'nginx:latest'
      ports: {
        web: {
          containerPort: 80
        }
      }
    }
  }
}

Note the frontend container doesn’t yet have a connection to the backend container. We will add that in the next step.

Step 2: Add a connection

With the services defined, we can now add the connection between them. Add a connection to frontend:

 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'frontend'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
      ports: {
        web: {
          containerPort: 3000
        }
      }
    }
    connections: {
      backend: {
        source: 'http://backend:80'
      }
    }
  }
}

Step 3: Deploy the application

Deploy the application using the rad deploy command:

rad run app.bicep -a networking-demo

You should see the application deploy successfully and the log stream start:

Building app.bicep...
Deploying template 'app.bicep' for application 'networking-demo' and environment 'default' from workspace 'default'...

Deployment In Progress...

Completed            backend         Applications.Core/containers
Completed            frontend        Applications.Core/containers

Deployment Complete

Resources:
    backend         Applications.Core/containers
    frontend        Applications.Core/containers

Starting log stream...

Step 4: Test the connection

Visit http://localhost:3000 in your browser. You should see a connection to the backend container, along with the environment variables that have automatically been set on the frontend container:

Done

You have successfully added a connection between two containers. Make sure to delete your application to clean up the containers:

rad app delete networking-demo -y