skip to Main Content
Back to Insights

Anyone who has written an iOS mobile application knows that using Core Data and SQLite is not for the fainthearted. And anyone who has read through the documentation for Apple’s NSPersistentStoreCoordinator was likely asleep before they had figured out how to retrieve any information from the database. Why is it, then, that SQLite became the default database for both iOS and Android?

It is probable that no one anticipated the increasing complexity of mobile applications and, more importantly, there was no alternative at the time. It was natural that Apple would reach for the mature, embedded SQLite database and that Google would follow in their footsteps. SQLite, though, was never built for mobile applications or the needs of the millions of mobile developers who would gravitate to the new platforms. SQLite was designed over 15 years ago for use on board the US Navy’s guided missile destroyers. The phrase ‘platform shift’ does not begin to adequately capture the difference between that environment and a modern cell phone. Nevertheless, there has been almost no investment in mobile databases since the design of SQLite 15 years ago[1]. And that is one of the reasons we are happy to announce our new investment in Realm. The team at Realm has built a database that has several critical advantages over SQLite:

1. Simple and Concise API

Compare the following two code snippets:

Realm

func saveRealmName(name: String) {
let realm = RLMRealm.defaultRealm()
realm.transactionWithBlock {
let person = Person()
person.name = name
realm.addObject(person)
}
}

SQLite

func saveCoreDataName(name: String) {
let appDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let managedContext = appDelegate.managedObjectContext!
let entity = NSEntityDescription.entityForName( Person ,
inManagedObjectContext: managedContext)
let person = NSManagedObject(entity: entity!,
insertIntoManagedObjectContext:managedContext)
person.setValue(name, forKey: name )
var error: NSError?
if !managedContext.save(&error) {
println( Could not save (error), (error?.userInfo) )
}
}

Developers want to be productive and write code that is simple yet expressive. Database functionality is well understood and represents a perfect opportunity to abstract away unnecessary complexity. Realm has solved this. Realm also has better support for native objects. Preserving the structure of objects as they move in and out of the database is a boon.

Usually, compact code is associated with higher-level languages (like Ruby & Python) that lose in performance what they gain in simplicity. But that leads one to Realm’s second big advantage.

2. 10-100x Faster

Realm is significantly faster than SQLite as the benchmark below shows:

As the storage available in mobile phones increases, databases will grow in both size and complexity. The drive to eliminate cellular network latency and improve the user experience on mobile devices will result in larger, local databases. Fast and responsive catalog search requires every product to be in database on the user’s phone. Once that happens, query performance will be critical.

3. Cross-Platform Consistency

The same Realm database can be used across both iOS and Android. This allows the same data model to be shared across both platforms and allows for greater code ‘reuse’ across the major mobile platforms, a huge advantage over the platform-specific frameworks that usually sit on top of SQLite.

Conclusion

We are very enthusiastic about our investment in Realm. In the short time since they launched the product it has already been widely adopted by mobile developers who relish an opportunity to improve the performance of their application while simultaneously improving code readability and scrapping a ton of boilerplate code. The team at Realm has tackled the long-neglected problem of building a better mobile database and we are excited to be partnering with them.

Notes

[1] Despite an explosion of investment in server side databases over the past decade, the timeline below shows the dearth of investment on the mobile side.

Back To Top