---
title: Creating Sync Groups
slug: v4-6/creating-sync-groups
docTags: 
createdAt: 2024-03-13T15:23:38.465Z
---

A sync group is a collection of devices organized into a distinct group, allowing you to limit connections to specific subsets of devices rather than the default behavior of connecting  all devices sharing the same app ID.&#x20;

# Introduction

By default, devices with the same app ID automatically form a mesh network to connect. However, you can streamline sync processes, minimize unnecessary data transfer, and optimize resource usage by configuring sync groups within your app.

For example, the following graphic illustrates two distinct restaurants identified by their location IDs: `7890` and `1234`. When a peer establishes its identity with the Big Peer, it includes its location ID as part of the authentication callback.&#x20;

Now, the two groups maintain isolated mesh networks:

::Image[]{src="https://api.archbee.com/api/optimize/qoRkNxW5fJ81r_NqVpc8C/K0lx1Dc3BcPZkOYysO3tB_syncgroups.png" size="92" width="872" height="391" position="flex-start" showCaption="false"}

# Access Controls by Group

Sync groups are an optimization, not a security control — if a connection is created manually, such as by specifying a connecting transport, then devices from different sync groups will still sync as normal.&#x20;

To enforce access controls by group, for instance, two groups of devices, each accessing different datasets, use Ditto's permissions system. (See [End-User Access](docId\:lqp70n83MJOB9wTojPNrW))

The `syncGroup` parameter provides this functionality. A device can only ever be in one sync group, which by default is group 0. Up to 2^32 distinct group numbers can be used in an app. Using a sync group is more performant, and is recommended in any case where this knowledge is known ahead of time.&#x20;

# Setting Up Sync Groups

To create a sync group:

:::CodeblockTabs
```swift
var config = DittoTransportConfig()
config.global.syncGroup = 1234

ditto.transportConfig = config

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

```kotlin
val config = DittoTransportConfig()
config.global.syncGroup = 1234U

ditto.transportConfig = config

ditto.startSync()
```

```javascript
const config = new TransportConfig()
config.global.syncGroup = 1234

ditto.setTransportConfig(config)

ditto.startSync()
```

```java
// not supported in Java
```

```csharp
DittoTransportConfig transportConfig = new DittoTransportConfig();
transportConfig.Global.SyncGroup = 1234;

ditto.TransportConfig = transportConfig;

ditto.StartSync();
```

```cpp
auto config = ditto::TransportConfig();
config.global.sync_group = 1234;

ditto.set_transport_config(config);

ditto.start_sync();
```

```rust
let mut config = TransportConfig::new();
config.global.sync_group = 1234;

ditto.set_transport_config(config);
ditto.start_sync()?;
```
:::

