Best Practices
5. Testing and Optimization

Testing Best Practices: Big Peers, Small Peers, and Identity Switching

Follow this guide to help you test changes you make to your Ditto integration code, data models, and business logic. In addition to their production app in the Portal, most developers operate two additional apps: one for development and another for staging. A staging instance is set up as a pre-release sandbox that can simulate real-world environments and data.

Big Peer

Testing in a cloud environment offers scalability, flexibility, and cost efficiency by allowing dynamic resource allocation and parallel testing. It provides consistent, reproducible environments for reliable results and supports advanced automated and performance testing capabilities.

In the Big Peer, each application is isolated from one another by default in a multi-tenant architecture, ensuring robust security and data privacy. This design allows multiple tenants to share the same infrastructure while keeping their data and applications completely separate.

The following approaches allow multiple developers to work on Ditto in parallel, without conflict.

  • App per environment (dev, stage, prod), prefix collections with developer environment
    • Each developer can work within the same app
    • Running tests in isolation can be done by prefixing the collection with a unique identifier specific to that developer
    • For example, a Collection named john_smith.orders.v3
  • App per developer
    • Each developer creates their own “app” within an organization. This creates a sandbox for a developer to isolate work and data from other developers
    • Starting a new test would require changing the AppID on the Small Peer

How do I migrate data between applications?

Please contact your dedicated support engineer to help migrate data between apps.

How to Reach Us:

  • Ditto Portal:
  • Email: Send an email to our support team at [email protected]
    • Please include the details of the apps you wish to help migrate data between.

Small Peer

To test Small Peer integration in isolation, we suggest using a wrapper library that includes an interface and mock implementation for unit testing. Ditto can be injected with an offline-only instance using an offline license token, and building a wrapper library includes an interface and a mock implementation for unit testing. This allows you to test small peer logic and syncing between small peers without relying on the availability of a Big Peer, which is great for testing within a CI/CD pipeline.

Identity Switching

When testing the production readiness of your app, it is best practice to incorporate dynamic identity switching to debug potential issues related to roles, permissions, sync, and authentication workflows, such as cleanup and resource management when changing identities within your app.

In dynamic identity switching, end-user types adjust in realtime as a response to specific contexts or situations, without requiring an app restart or code change. From the end-user perspective, this automatic process means no interruptions or inconveniences like needing to log in again.

While testing with different digital identities is recommended during pre-production testing, this practice is not recommended for production environments due to potential performance and security concerns.

To incorporate the process of automatically changing end-user types at runtime:

Swift
Kotlin
JS
Java
C#
C++
Rust


Ditto will persist data on each device. Data within the sandboxed application will be treated as new data and continue to sync, even if the developer changes the AppID. We suggest changing the persistence directory to prepend the appId to the path to avoid this.

See the example projects in GitHub for testing the Small Peer by leveraging the OfflinePlayground identity and changing the persistence directory to prepend the appId to the path.

Example Usage in iOS App

For a realworld implementation of switching user identities in Swift, see the DittoToolsApp in the getditto > DittoSwiftTools repository on GitHub.

In this implementation, the DittoManager method class configures, manages, and interacts with authentication functionality in the app.

FAQ

Can I mock the big peer or small peer for CI use?

  • We don’t have anything to provide today.

Can I run the Big Peer on my local laptop?

  • We don’t have this yet, but it’s on the roadmap.

Is it a problem to have multiple apps?

  • No, it is designed for multi-tenancy.