With last week’s release of version 1.15.0 (appropriately codenamed “Lawrence of Arabia”), RethinkDB has finally (did I just say finally?) added one of the most-requested features: Geospatial support. Sporting a shiny new set of geo types, functions, and indexes, it’s harder than ever to find excuses not to try RethinkDB.
Several of my current skunkworks projects involve geospatial data in one way or another. RethinkDB’s lack of support was sending me back to Postgres, which, while mature and feature-filled, is also a bit of an overcomplicated mess. Attempts to make PostGIS easier to use, like ORM add-ons, instead tend to make things even more complicated. (The ActiveRecord adapter, for example, wants to store geographies — but for many applications, many of the functions you’ll want operate only on geometries, meaning you have to cast every. single. query.)
RethinkDB’s geo support, on the other hand, is a reimagining of what people actually want in geospatial functions in today’s applications. Want to do a KNN search? No sweat. getNearest
has you covered. Need to find some intersecting areas? getIntersecting
, duh. Circles and points are easily created with circle
and point
. It’s so humane it will blow your mind.
Postgres with PostGIS is currently a lot faster for nearest neighbor searches—we’re talking at least an order of magnitude—but I still find RethinkDB more pleasant to use. Not only is ReQL’s getNearest
much easier to remember, but the way ReQL is evaluated means I don’t get the SQL Injection Heebie Jeebies every time I have to work with location data from the big bad outside world.
Curiously, getIntersecting
does not suffer from getNearest
‘s performance issues. It’s instead right on par with PostGIS, and — if the very idea doesn’t make you feel dirty — can even be used to get near-PostGIS KNN performance out of RethinkDB in most applications. (Imagine for a moment you’re making a Yelp competitor. We don’t care about the true K nearest neighbors so much as what’s immediately around the user. If you’re scoping to, say, 5 miles anyway, who cares what the query looks like as long as the results are useful? Call getIntersecting
with a 5 mile circle originating at the user’s location. Bam!)
It’s an exciting time to be playing with location-based apps! While I haven’t used every data store out there, RethinkDB 1.15 has made things much simpler than anything I’ve used to this point.