| 1 | # Technical concept DPF Selector |
| 2 | |
| 3 | This document presents the technical concept for the "DataPlaneFramework Selector", henceforth "DPF Selector" or "DPFS" |
| 4 | for short. In typical clustered environments (Kubernetes) we anticipate a multitude of connector runtimes and DPF |
| 5 | runtimes, scaling independently of each other, depending on a particular use case. Also, the DPFs may have different |
| 6 | configurations, so they may not even be in the same replica set (in Azure this would be Availability Sets vs. Scale |
| 7 | Sets). |
| 8 | |
| 9 | Further, we assume that every connector has access to multiple DPF runtimes, even if they are not homogenous replicas. |
| 10 | For example, some deployments may choose to have one dedicated DPF per geographical region, or even per `DataSink` |
| 11 | /`DataSource` pair. |
| 12 | |
| 13 | Whenever a data transfer request hits the connector, it eventually will delegate the transfer to the DPF. For that, it |
| 14 | needs to know _which DPF to delegate to_. In simple deployments, there may just be one single DPF, so the DPF selector |
| 15 | is essentially a preconfigured value, but in more complex scenarios sophisticated algorithms may be employed to select |
| 16 | the best-fitting DPF. |
| 17 | |
| 18 | This is not dissimilar to how load-balancers work, one key difference being that the DPF selector will distribute the |
| 19 | request based on not just the load situation, but also based on request metadata or even functional requirements (e.g. " |
| 20 | must be able to store in Azure BlobStore"). |
| 21 | |
| 22 | Another key difference to (most) load balancers is the modularity and flexibility of the DPF selector: it can be |
| 23 | embedded into another process (e.g. a connector), standalone, it can handle different storage and API technologies, it |
| 24 | itself could theoretically run clustered, etc. |
| 25 | |
| 26 | ## Terminology |
| 27 | |
| 28 | - DPF: one DataPlaneFramework runtime instance |
| 29 | - CP: one ControlPlane instance, often used synonymous to "connector" |
| 30 | - connector: one connector runtime |
| 31 | - selector: one DPF selector runtime, either embedded or standalone |
| 32 | - DataSource: one particular implementation that the DPF uses to fetch data from (e.g. Amazon S3) |
| 33 | - DataSink: one particular implementation of a data destination (e.g. AzureBlob) |
| 34 | - Seeding: the process of pre-populating a database. Often used synonymous to "loading". |
| 35 | - Feature pack: a collection of Java modules that fulfill one particular purpose, typically accompanied by a BOM ( |
| 36 | bill-of-materials) |
| 37 | |
| 38 | ## Proposed solution |
| 39 | |
| 40 | We propose to create another "feature pack" in the EDC repository, essentially a meta module |
| 41 | named `:extensions:data-plane-selector`, which will contain (at least) the following submodules: |
| 42 | |
| 43 | - `selector-spi`: for interfaces and extensibility points such as store, strategy |
| 44 | - `data-plane-selector-api`: REST API |
| 45 | - `selector-core`: common code, default implementations for store and strategies |
| 46 | |
| 47 | Furthermore there should be a `selector-launcher` in the `launchers` directory containing a build file for standalone |
| 48 | deployment. |
| 49 | |
| 50 | Centrally to the DPF selector is an interface `DataPlaneSelector` whos purpose is to select a DPF instance based on an |
| 51 | incoming `DataRequest` and an optional `SelectionStrategy`: |
| 52 | |
| 53 | ```java |
| 54 | public interface DataPlaneSelector { |
| 55 | |
| 56 | default DataPlaneInstance select(DataRequest dataRequest) { |
| 57 | return select(dataRequest, new RandomSelectionStrategy()); |
| 58 | } |
| 59 | |
| 60 | DataPlaneInstance select(DataRequest dataRequest, SelectionStrategy strategy); |
| 61 | } |
| 62 | ``` |
| 63 | |
| 64 | The main business object is the `DataPlaneInstance` which represents one particular DPF instance with circa the |
| 65 | following signature: |
| 66 | |
| 67 | ```java |
| 68 | public interface DataPlaneInstance { |
| 69 | boolean canHandle(DataRequest request); |
| 70 | |
| 71 | URL getUrl(); //returns the url+path to the DataPlane API |
| 72 | |
| 73 | int turnCount(); //how often selected |
| 74 | |
| 75 | long lastActive(); //when selected last |
| 76 | |
| 77 | Map<String, Object> getProperties(); //extensible properties |
| 78 | } |
| 79 | ``` |
| 80 | |
| 81 | Thus, the `DataPlaneInstance` itself determines whether it can support a particular data request, based on various |
| 82 | capabilities such as its `DataSink` and `DataSource` implementations, streaming capabilities, etc. |
| 83 | |
| 84 | Requests come in either through an API or an SPI hit the `DataPlaneSelector`, which then filters its list |
| 85 | of `DataPlaneInstace` records and selects the best fitting DPF based on a strategy. By default selection is made at |
| 86 | random. |
| 87 | |
| 88 | ### API/SPI considerations |
| 89 | |
| 90 | We'll provide both a REST API and a Java SPI (i.e. the `DataPlaneSelector`), so that the DPF selector can run embedded |
| 91 | in another process, or as a standalone runtime. Both of those should offer the same functionality, which is: |
| 92 | |
| 93 | - `get-instance`: selects the best-fit DPF for a `DataRequest`, optionally accepts a `SelectionStrategy` |
| 94 | - `add-instance`: adds a `DataPlaneInstance` to the internal store |
| 95 | - `remove-instance`: removes a `DataPlaneInstance` from the internal store |
| 96 | |
| 97 | Both the REST API and the SPI implement these use cases. |
| 98 | |
| 99 | ### Single vs Multi DPF |
| 100 | |
| 101 | In case a particular deployment uses just one DPF, the entire selection process can be simplified to always return the |
| 102 | pre-configured DPF URL. This is likely to be used in end-to-end-test scenarios, demos or samples. |
| 103 | |
| 104 | ### Store concepts |
| 105 | |
| 106 | The DPF selector needs a storage backend where it can save its `DataPlaneInstance` objects. The default implementation |
| 107 | will be an in-memory one, but extensions can be provided for CosmosDB, SQL, etc. |
| 108 | |
| 109 | Whether a centralized persistent or an ephemeral store should be used will largely depend on the deployment scenario and |
| 110 | whether the DPF selector runs standalone or embedded in the connector. |
| 111 | |
| 112 | **Seeding:** As a starting point we will provide a mechanism to load a preconfigured list of DPF instances using the EDC |
| 113 | configuration mechanism. Named properties similar will be used, similar to what we currently have for web contexts, for |
| 114 | example: |
| 115 | |
| 116 | ```properties |
| 117 | edc.dpf.selector.pod1.url=http://some.url |
| 118 | edc.dpf.selector.pod1.someOtherProperty=... |
| 119 | //...= |
| 120 | edc.dpf.selector.pod2.url=http://some.other.url |
| 121 | edc.dpf.selector.pod2.someOtherProperty=... |
| 122 | ``` |
| 123 | |
| 124 | In addition, using the aforementioned API, any sort of data seeding scenario is possible, e.g. terraform, a dedicated |
| 125 | loader, scripting, etc. |
| 126 | |
| 127 | ### Selection Strategies |
| 128 | |
| 129 | A `SelectionStrategy` (as in: [strategy pattern](https://en.wikipedia.org/wiki/Strategy_pattern)) influences the |
| 130 | best-fit criteria for a `DataPlaneInstance`. By default, we will implement the following ones: |
| 131 | |
| 132 | - `RandomSelectionStrategy`: will select one DPF instance at random. Assuming normal distribution of the RNG, all DPFs |
| 133 | will be selected at approximately equal frequency. |
| 134 | - `RoundRobinSelectionStrategy`: selects the "next" DPF instance in an ordered list. **Requires state!** |
| 135 | - [optional] `OldestNextSelectionStrategy`: selects the DPF instance that was idle the longest |
| 136 | |
| 137 | _Please note that when multiple DPF selector instances are used, some of the selection strategies only work as intended |
| 138 | if DPF selectors share their storage, otherwise the counters would be inconsitent!_ |
| 139 | |
| 140 | All `SelectionStrategy` objects must be registered with the DPF selector before it can be passed in through a REST API |
| 141 | or used in the SPI. This requires the use of a `SelectionStrategyRegistry` into which customer extensions can register |
| 142 | their specific strategies. |
| 143 | |
| 144 | ## Deployment scenarios |
| 145 | |
| 146 | With this modular approach, the DPF selector can run as a standalone application, for example in a Kubernetes Deployment |
| 147 | or as plain sidecar container. However, this type of deployment scenario practically _requires_ adding the `-api` module |
| 148 | to the build, otherwise no interaction with the selector is possible. |
| 149 | |
| 150 | Another way of running a DPF selector would be as extension, i.e. embedded in an EDC connector runtime. In this scenario |
| 151 | the `-api` module can be ignored, as all communication happens through the Java SPI. Again, situations with multiple |
| 152 | connector instances practically _require_ using a persistent centralized storage (such as CosmosDB). |
| 153 | |
| 154 | **Client lib**: it should be transparent for the connector whether an embedded or a remote DPF selector is used, |
| 155 | therefore we propose creating a small "DPF selector lib" in the EDC codebase, consisting of a single interface: |
| 156 | |
| 157 | ```java |
| 158 | public interface DataPlaneSelectorClient { |
| 159 | DataPlaneInstance select(DataRequest dataRequest); |
| 160 | } |
| 161 | |
| 162 | // when the DPF selector is embedded --> default |
| 163 | class LocalDataPlaneSelectorClient implements DataPlaneSelectorClient { |
| 164 | private final DataPlaneSelector selector; |
| 165 | private SelectionStrategy strategy; //could be null |
| 166 | |
| 167 | // CTor(s) |
| 168 | |
| 169 | public DataPlaneInstance select(DataRequest dataRequest) { |
| 170 | return strategy != null ? selector.select(dataRequest, strategy) : selector.select(dataRequest); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // when the DPF selector is remote |
| 175 | class RemoteDataPlaneSelectorClient implements DataPlaneSelectorClient { |
| 176 | private final EdcHttpClient client; |
| 177 | private String strategyName; //could be null |
| 178 | |
| 179 | // CTor(s) |
| 180 | |
| 181 | public DataPlaneInstance select(DataRequest dataRequest) { |
| 182 | //invoke REST API of the remote selector |
| 183 | } |
| 184 | } |
| 185 | ``` |
| 186 | |
| 187 | ## Future developments |
| 188 | |
| 189 | Once we have performance metrics and instrumentation built-in into the DPF, we can create a small extension that reports |
| 190 | those dynamic metrics back to the DPF selector, who then stores them and uses them as additional input parameter to the |
| 191 | selection algorithm. |
| 192 | |
| 193 | Another possible improvement would be a DPF selector that can interact with the Kubernetes backend and dynamically |
| 194 | update its internal storage based on Kubernetes auto-scaling: when Kubernetes scales out the DPF pods, the selector |
| 195 | tracks that and automatically updates its internal storage. |