MongoSF - mongodb @ foursquare
- 2. what is foursquare?
location-based social network - “check-in” to bars,
restaurants, museums, parks, etc
friend-finder (where are my friends right now?)
virtual game (badges, points, mayorships)
city guide (local, personalized recommendations)
location diary + stats engine (where was I a year ago?)
specials (get rewards at your favorite restaurant)
- 4. foursquare: the tech
Nginx, HAProxy
Scala, Lift
MongoDB, PostgreSQL (legacy)
(Kestrel, Munin, Ganglia, Python, Memcache, ...)
All on EC2
- 6. mongodb: our numbers
8 clusters
some sharded, some not
some master/slave, some replica set
~40 machines (68.4GB, m2.4xl on EC2)
2.3 billion records
~15k QPS
- 7. mongodb: lessons learned
keep working set in memory
avoid long-running queries (reads or writes)
monitor everything (especially per-collection stats)
shard from day 1
beware EBS
use small field names for large collections
- 14. mongodb: pain points
mongos -- failover and thundering herds
index creation -- production impact unclear
auto-balancing -- getting there
replication chains -- use replica sets
- 15. rogue: a scala dsl for mongo
type-safe
all mongo query features
logging & validation hooks
pagination
index-aware
http://github.com/foursquare/rogue
- 17. rogue: code example
Venue where (_.mayorid <= 100)
and (_.venuename eqs “Starbucks”)
and (_.tags contains “wifi”)
and (_.latlng near
(39.0, -74.0, Degrees(0.2))
orderDesc (_._id)
fetch (5)
- 18. rogue: schema example
class Venue extends MongoRecord[Venue] {
object _id extends ObjectIdField(this)
object venuename extends StringField(this)
object mayorid extends LongField(this)
object tags extends ListField[String](this)
object latlng extends LatLngField(this)
}
- 19. rogue: logging & validation
logging:
slf4j
Tracer
validation:
radius, $in size
index checks
- 23. rogue: index-aware
val vs: List[Checkin] =
(Checkin
where (_.userid eqs 646)
and (_.venueid eqs vid) // hidden scan!
fetch ())
- 24. rogue: index-aware
val vs: List[Checkin] =
(Checkin
where (_.userid eqs 646) // known index
scan (_.venueid eqs vid) // known scan
fetch ())
- 25. rogue: future directions
iteratees for cursors
compile-time index checking
select partial objects
generate full javascript for mapreduce
- 26. we’re hiring
(nyc & sf)
http://foursquare.com/jobs
jorge@foursquare.com
@jorgeortiz85
Editor's Notes
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n
- \n