Sync behavior 'downloadBeforeOpen' too slow

Hi community,

I’m having some issues regarding the initialization of realm sync on the Atlas App Service and I couldn’t quite understand what are the reasons for it being so slow. After logging into the app, realm is initialized (via jwt) and sync is established (or at least it should be). The issue is that my sync settings are set to ‘downloadBeforeOpen’ and there is a slow download of the files to be synced, which leads to a timeout of 5 minutes and so throws an exception as we defined on the property timeOutBehavior.

What I can’t really get is that my application is utilizing Cluster Tier M30 and that my 18 collections size up to less than 200MB or even when I’m logging in and get the bytes that were transferred by using addProgressNotification a size much bigger appears to be downloaded on the sync process.

I would really use some help to try to figure out this slow sync process:

  1. Is my data too big?
  2. Does my code have any problem?
  3. Is it related to any instability in the Atlas App Service?
  4. Isn’t Cluster Tier M30 enough?
  5. Why is the progress notification showing many more bytes to download than my database has?

Configuração do sync atual:

    const realmFileBehavior: OpenRealmBehaviorConfiguration = {
      type: 'downloadBeforeOpen'
      timeOut: 1000 * 60 * 5, // 5 minutes
      timeOutBehavior: 'throwException',
    };

    this.realmConfig = {
      schema: this.config.schema,
      schemaVersion: this.config.schemaVersion,
      sync: {
        user: this.app!.currentUser!,
        partitionValue: this.config.partition,
        existingRealmFileBehavior: realmFileBehavior,
        newRealmFileBehavior: realmFileBehavior,
        error: this.errorSync,
        clientReset: {
          mode: 'discardLocal' 
        },
      },
    };
  }

The code to logIn and open the database:

// logIn =>

public async login(): Promise<void> {
    if (!this.app) {
      throw new Error('Realm app is not created');
    }

    const credentials = Realm.Credentials.jwt(this.accessToken);

    try {
      await this.app.logIn(credentials);
    } catch (err) {
      this.logger.warn(err);
    }

    if (!this.app?.currentUser) {
      throw new Error('Realm login failed: current user not found');
    }
  }

// openDatabase =>
  private async openDatabase(callback?: ProgressNotificationCallback) {
    const openingRealm = Realm.open(this.realmConfig!);

    if (callback) {
      this.realm = await openingRealm.progress(callback);
    } else {
      this.realm = await openingRealm;
    }
    this.openedDatabase = true;
  }

The cluster tier in use:

Cluster tier M30
Regis - AWS / N. Virginia

Database informations:

Logical Data Size: 164.77 MB
Storage Size: 114.44 MB
Index Size: 8.06 MB
Total Colections: 18

Other relevant information:

I'm using partition-based sync.
The biggest collection has 78K registers, totalizing 66.34 MB

_partition:1 (private)
 LOG  {"transferableBytes": 1283783226, "transferredBytes": 1404454}
transferable: 1,283.78 MB (why so big)

_partition:2 (public)
 LOG  {"transferableBytes": 253745684, "transferredBytes": 6133010}
transferable: 253.74 MB

There was an issue that I was notified of by users that have uninstalled the app and installed it again, as they tried to log in once more they could sync much faster than they were while trying to keep downloading what have been transferred to their device. What could explain this behavior?