# Enabling Dynamic Peers

This page provides a guide to using the new Dynamic Peers feature in Platform 8.

**Available from:** Platform 8

## Overview

Dynamic Peers is a new feature in Platform 8 that allows the removal of `add-peer` configuration items for incoming peer connections, allowing you to dynamically scale the number of provider peers (commonly adapters) at runtime.

For a more detailed overview, see the [Dynamic Peers](../datasource/datasource-dynamic-peers.md) feature overview.

## Converting from static to Dynamic Peers

The steps in this section use the following basic deployment as a worked example:

```plantuml
[Liberator1\n<color:gray>192.168.1.100</color>] as Liberator1
[PricingAdapter1]

PricingAdapter1 -right-> Liberator1

note bottom of Liberator1
<color:blue>~# Incoming peer connection</color>
add-peer
  remote-label PricingAdapter1
end-peer

add-data-service
    service-name PricingService
    add-source-group
        add-priority
            remote-label PricingAdapter1
        end-priority
    end-source-group
end-data-service
end note

note bottom of PricingAdapter1
<color:blue>~# Outgoing peer connection</color>
add-peer
  remote-label Liberator1
  addr 192.168.1.100
end-peer
end note
```

Follow the steps below:

1. In the Liberator configuration, remove the `add-peer` configuration for the incoming peer connection:

   ```plantuml
   [Liberator1\n<color:gray>192.168.1.100</color>] as Liberator1
   [PricingAdapter1]

   PricingAdapter1 -right-> Liberator1

   note bottom of Liberator1
    --<color:red>~# Incoming peer connection</color>--
    --<color:red>add-peer</color>--
      --<color:red>remote-label PricingAdapter1</color>--
    --<color:red>end-peer</color>--

   add-data-service
       service-name PricingService
       add-source-group
           add-priority
               remote-label PricingAdapter1
           end-priority
       end-source-group
   end-data-service
   end note

   note bottom of PricingAdapter1
   <color:blue>~# Outgoing peer connection</color>
   add-peer
     remote-label Liberator1
     addr 192.168.1.100
   end-peer
   end note
   ```
2. In the Liberator configuration, edit the data service definition that routes to the peer. Instead of referencing specific peer labels, switch to referencing peer labels by regular expression (`remote-label-regex`):

   ```plantuml
   [Liberator1\n<color:gray>192.168.1.100</color>] as Liberator1
   [PricingAdapter1]

   PricingAdapter1 -right-> Liberator1

   note bottom of Liberator1
    --<color:red>~# Incoming peer connection</color>--
    --<color:red>add-peer</color>--
      --<color:red>remote-label PricingAdapter1</color>--
    --<color:red>end-peer</color>--

   add-data-service
       service-name PricingService
       add-source-group
           add-priority
               <color:red>--remote-label PricingAdapter1--</color>
               <color:green>remote-label-regex ^PricingAdapter[0-9]+</color>
           end-priority
       end-source-group
   end-data-service
   end note

   note bottom of PricingAdapter1
   <color:blue>~# Outgoing peer connection</color>
   add-peer
     remote-label Liberator1
     addr 192.168.1.100
   end-peer
   end note
   ```
3. In the adapter configuration, declare the adapter a provider of the service 'PricingService', matching the name of the related data service in Liberator:

   ```plantuml
   [Liberator1\n<color:gray>192.168.1.100</color>] as Liberator1
   [PricingAdapter1]

   PricingAdapter1 -right-> Liberator1

   note bottom of Liberator1
    --<color:red>~# Incoming peer connection</color>--
    --<color:red>add-peer</color>--
      --<color:red>remote-label PricingAdapter1</color>--
    --<color:red>end-peer</color>--

   add-data-service
       service-name PricingService
       add-source-group
           add-priority
               <color:red>--remote-label PricingAdapter1--</color>
               <color:green>remote-label-regex ^PricingAdapter[0-9]+</color>
           end-priority
       end-source-group
   end-data-service
   end note

   note bottom of PricingAdapter1
   <color:blue>~# Outgoing peer connection</color>
   add-peer
     remote-label Liberator1
     addr 192.168.1.100
   end-peer

   <color:green>discovery-provide-service PricingService</color>
   end note
   ```
4. In the adapter configuration, assign the adapter a unique local label, either with the option `add-peer:local-label` or the global item `datasrc-local-label`.

   ```plantuml
   [Liberator1\n<color:gray>192.168.1.100</color>] as Liberator1
   [PricingAdapter1]

   PricingAdapter1 -right-> Liberator1

   note bottom of Liberator1
    --<color:red>~# Incoming peer connection</color>--
    --<color:red>add-peer</color>--
      --<color:red>remote-label PricingAdapter1</color>--
    --<color:red>end-peer</color>--

   add-data-service
       service-name PricingService
       add-source-group
           add-priority
               <color:red>--remote-label PricingAdapter1--</color>
               <color:green>remote-label-regex ^PricingAdapter[0-9]+</color>
           end-priority
       end-source-group
   end-data-service
   end note

   note bottom of PricingAdapter1
   <color:blue>~# Outgoing peer connection</color>
   add-peer
     remote-label Liberator1
     addr 192.168.1.100
   end-peer

   <color:green>discovery-provide-service PricingService</color>

   <color:green>datasrc-local-label PricingAdapter1</color>
   end note
   ```
5. Restart the adapter and Liberator
