In an R&D company fast prototyping is vital to develop new projects or proofs of concept quickly and inexpensively. In this talk we will demonstrate how real fast and agile development can be achieved with MongoDB and dynamic languages, with examples and best practices. All the code shown is already uploaded to a public Git repository - https://github.com/pablito56/py-eshop
1. FAST REST APIS DEVELOPMENT
WITH MONGODB
Pablo Enfedaque Vidal
@pablitoev56
2. WHO?
• Pablo Enfedaque
• Computers Engineer
• Tech Lead and R&D software engineer at Telefonica Digital
• Working with MongoDB for some years.
3. TELEFONICA DIGITAL. WHAT?
• Telefonica
• Fifth largest telecommunications company in the world
• Operations in Europe (7 countries), the United States and
Latin America (15 countries)
• Movistar, O2, Vivo, Terra, Tuenti, Jahjah, Tokbox,
everything.me, Open Web Device…
4. TELEFONICA DIGITAL. WHAT?
• Telefonica Digital
• Web and mobile digital contents and services division
• Product Development and Innovation unit
• Products & services development, research, technology
strategy, user experience, deployment & operations…
• Around 70 different on going projects
5. OUR PROJECTS
• Full product development, with life cycle and several deployments
• 20 people team, 1 year or more
• Pilot or small product to be deployed in a certain environment
• 6 people team, 6 months
• Seedbed or proof of concept to be run with reduced set of users
• 3 people team, 3 months
• Ten Fridays open exploratory project to work on your ideas
• 2 people team, 10 days (consecutive Fridays)
12. THE RIGHT TECHNOLOGY
• Several times faster development with Dynamic Languages
• Several times faster development with MongoDB
AND BOTH TOGETHER IS A
WIN WIN
15. JAVA VERSION
public int[] getDims() {
if (this.dims != null) {
return this.dims;
}
BasicDBObject query = new BasicDBObject();
query.put("_id", "ctxt_dimensions");
DBObject setup = setup_coll.findOne(query);
BasicDBList dbl = (BasicDBList)setup.get("dims");
this.dims = new int[dbl.size() + 2];
BasicDBObject users_counter_ref = new BasicDBObject("_id", users_coll_name);
BasicDBObject apps_counter_ref = new BasicDBObject("_id", apps_coll_name);
dims[0] = (Integer)counters_coll.findOne(users_counter_ref).get("value") + 1;
dims[1] = (Integer)counters_coll.findOne(apps_counter_ref).get("value") + 1;
for (int i=0; i<dbl.size(); i++) {
dims[i + 2] = (Integer)dbl.get(i);
}
return dims;
}
16. PYTHON VERSION
def get_dims(self):
ud = self.counters_coll.find_one({'_id': 'users'})['value']
ad = self.counters_coll.find_one({'_id': 'applications'})['value']
res = [ud, ad]
res.extend(self.setup_coll.find_one({}, {'dims': 1})['dims'])
return res
IT’S UP TO YOU…
39. CONCLUSIONS
• MongoDB + dynamic languages = fastest development speed
• 14 months project with Oracle à 3 months project with MongoDB
• REST API best practices
• Use JSON
• Use dictionaries / hashes
• Access dictionaries as objects
• No relational model à no ORM
• No other mappers
• Use decorators to handle AutoReconnect