Search code examples
mongodbrealmrealm-mobile-platform

Using Realm Sync with Atlas increases my app size drastically


I am using Realm for my application because of it's offline first approach. My app will send lots of images to db/Atlas.

I observed that my app size is getting increased. I am wondering that it's storing all data including all images locally as well in all devices for offline availability.

So my question is when my data size keeps on increasing and suppose it reach 10 Gb of space, will my app be able to handle this and what my app size will be. Will it be 10 Gb? What can I do to handle it and what are the dos and don't s to handle it?


Solution

  • Realm is primarily a database that also happens to offer synchronization features. So when you say you're sending lots of images to Atlas, it means you're storing them in the local Realm database, which then uploads them to Atlas in the background. One way to reduce your local storage and optimize data usage is to instead upload the images to S3/Azure Blob Storage and only store their urls in Realm/Atlas. I have a project that does that for C#, but it's a few hundred lines of code that can easily be ported to another language.

    The benefits of doing it that way are threefold:

    1. You load/cache images on demand rather than storing them along with your data. There are many libraries (e.g. SDWebImage) that handle downloading, caching, and displaying the images.
    2. You can use a server-side function to generate thumbnails/different image sizes whenever an image is uploaded, making it faster to display the image on different devices.
    3. You can configure/take advantage of CDNs to move the binary data closer to your end users and reduce latency.