Introduction
Realm is an object-oriented mobile database built from the ground up as an alternative to SQLite and Core Data. It stores native objects directly, eliminating the object-relational mapping layer. Realm is available for Swift, Kotlin, Java, C#, and JavaScript (React Native), providing a consistent data layer across mobile platforms.
What Realm Does
- Stores native language objects without manual serialization or ORM boilerplate
- Delivers lazy-loaded query results with zero-copy reads for fast performance
- Provides live objects that update automatically when underlying data changes
- Supports cross-platform data models for iOS, Android, and React Native
- Optionally syncs with MongoDB Atlas Device Sync for real-time cloud backup
Architecture Overview
Realm uses a custom C++ storage engine based on a memory-mapped B+ tree. Data is written in a multiversion concurrency control (MVCC) format, allowing readers and writers to operate without blocking each other. Platform-specific SDKs wrap the core engine and expose idiomatic APIs. Queries are lazy — results are not materialized until accessed.
Self-Hosting & Configuration
- Add the Realm SDK via Swift Package Manager, CocoaPods, Gradle, or npm
- No server is needed for local-only usage — data lives in a .realm file on device
- Configure file location, encryption key, and schema version at Realm initialization
- Enable Atlas Device Sync by connecting to a MongoDB Atlas backend (optional)
- Schema migrations are defined in code and run automatically on version bumps
Key Features
- Zero-copy architecture reads data directly from memory-mapped files
- MVCC concurrency allows simultaneous reads and writes without locks
- Live objects and collection notifications power reactive UI patterns
- AES-256 encryption protects the database file at rest
- Compact file format keeps storage footprint small on mobile devices
Comparison with Similar Tools
- SQLite — relational with SQL queries; Realm uses native object APIs and avoids ORM
- Core Data — Apple-only framework on top of SQLite; Realm is cross-platform and simpler
- Room (Android) — SQLite abstraction for Android; Realm offers reactive objects and cross-platform support
- WatermelonDB — built on SQLite for React Native; Realm has its own engine and broader platform coverage
FAQ
Q: Is Realm free to use? A: The local database SDKs are free and open source under Apache 2.0. Atlas Device Sync is a paid MongoDB service.
Q: Can Realm handle large datasets on mobile? A: Yes. The lazy query engine and memory-mapped storage handle millions of objects efficiently on device.
Q: Does Realm support SQL queries? A: No. Realm uses its own query syntax with type-safe predicate builders in each language SDK.
Q: What happens to data when the app is deleted? A: The .realm file lives in the app sandbox and is removed with the app unless backed up to a cloud sync service.