Overview

When using the Ditto Server optional cloud deployment and managing large document collections, you can group peers with similar data access patterns by assigning specific labels, known as routing hints.

Represented as an unsigned integer with 32 bits (uint32), a routing hint is a value you define at the device level that Ditto Server references to optimize connections with peers consuming the same datasets.

Example Usage Scenario

In a scenario where several restaurants operate on the same Ditto Server instance and devices within each restaurant share the same data, assigning a single routing hint across peers within each restaurant optimizes individual peer connections with the Ditto Server.

Implementing Routing Hints

To set a routing hint in your app, from the top-most scope before starting the sync process:

1

Instantiate a `TransportConfig` object:

var config = DittoTransportConfig()
config.global.routingHint = 1234

ditto.transportConfig = config

do {
  try ditto.startSync()
} catch (let error) {
  print(error.localizedDescription)
}
2

Set the `routingHint` on the `config`object:

var config = DittoTransportConfig()
config.global.routingHint = 1234

ditto.transportConfig = config

do {
  try ditto.startSync()
} catch (let error) {
  print(error.localizedDescription)
}
3

Using the `TransportConfig` object, specify the configuration settings for your Ditto instance:

var config = DittoTransportConfig()
config.global.routingHint = 1234

ditto.transportConfig = config

do {
  try ditto.startSync()
} catch (let error) {
  print(error.localizedDescription)
}