Upgrade to Pro — share decks privately, control downloads, hide ads and more …

What's in a Mobile Database?

What's in a Mobile Database?

4d6be90af74894fd132fb06dacec04d7?s=128

Samuel E. Giddins

March 03, 2015
Tweet

More Decks by Samuel E. Giddins

Other Decks in Technology

Transcript

  1. WHAT’S IN A MOBILE DATABASE?

  2. SAMUEL GIDDINS REALM.IO

  3. Show of hands: WHO’S USED A DATABASE?

  4. LET’S NAME SOME

  5. MOST OF THOSE ARE SERVER DATABASES

  6. None
  7. SQLITE THE STATUS QUO

  8. ▸ Single-threaded ▸ Dynamically-typed ▸ Weakly-typed ▸ Designed in 2000

  9. WHAT ARE OUR CONSTRAINTS?

  10. ▸ Running on a device ▸ Can’t update database code

    on a whim ▸ Little RAM ▸ Relatively few CPU cores ▸ Multiple processes ▸ Long-running use of data
  11. WHAT DO WE WANT TO OPTIMIZE FOR?

  12. ▸ Querying ▸ Reading values ▸ Maintainable API ▸ Safe

    Migrations ▸ Static + Dynamic Schemas
  13. THE GOALS

  14. ▸ Cross-platform ▸ Memory-mapped ▸ Thread-safe ▸ Object-oriented ▸ Blazing

    fast ▸ Sane interface
  15. CROSS PLATFORM

  16. People build services that need to run on multiple platforms.

    Their database should reflect this.
  17. MEMORY MAPPING

  18. void *mmap( void *addr, size_t length, int prot, int flags,

    int fd, off_t offset ); This function is magical.
  19. Blur the line between in-memory and on-disk to get the

    best of both worlds. Take advantage of optimizations in the kernel and let it do the hard work for you.
  20. THREAD SAFETY

  21. THREAD SAFETY PERHAPS THE MOST LOADED WORD IN CS

  22. WELL-DEFINED THREADING MODEL ▸ What can be passed between threads?

    ▸ How easily can I isolate things that can’t be?
  23. Built with speed & safety in mind: ▸ No reader

    lock ▸ Allow concurrent reading & writing ▸ Let the user know when they violate the threading contract
  24. OBJECT-ORIENTED API

  25. ▸ First-class model objects ▸ Support for persisted + in

    memory objects ▸ No invisible web of classes
  26. BLAZING FAST

  27. WHY SHOULD OBJECTS AND THE DATABASE EVER GROW APART?

  28. WHY SHOULD OBJECTS AND THE DATABASE EVER GROW APART? OR

    WHERE ORMS WENT WRONG
  29. ▸ Lazily create objects in memory ▸ Access & set

    values directly in the DB ▸ Optimized query engine
  30. SANE API

  31. ▸ What do I need a reference to? ▸ Platform

    coherence ▸ Isolate DB interaction ▸ Make it impossible to mess up
  32. LET’S RECAP

  33. ▸ Cross-platform ▸ Memory-mapped ▸ Thread-safe ▸ Object-oriented ▸ Blazing

    fast ▸ Sane interface
  34. SOUNDS A LOT LIKE THE DREAM, RIGHT?

  35. Make persistence just another aspect of your data, instead of

    a whole convoluted system.
  36. ⾠ This might not be the approach for everyone. Take

    a look at the goals, and see if they align with your own.
  37. My company, Realm, is working towards building a database that

    hits these bullet points. I’m not here to sell you on Realm. But building something that mirrors those goals is why we exist.
  38. EXAMPLES?

  39. Available now on Speaker Deck. https://speakerdeck.com/segiddins/whats-in-a-mobile-database

  40. db.objects(Question).map { $0.ask }

  41. SAMUEL GIDDINS REALM.IO @SEGIDDINS