Post on 18-Jul-2015
ABOUT ME.
• Programming as a hobby.
• Final student, NTU (Biz IT).
• Mainly involved in tech-related
entrepreneurial projects.
• Latest project is
VogueVerve.com.
CONTENTS.
• Nodejs
• Expressjs
• Node modules
– Passport
– Sequelize
– Bluebird
• Postgres, Mongo, Couchbase
WHAT IS NODEJS?
• It is a server side Javascript
runtime environment.
• Powered by Chrome V8.
• Main intention of real-time
communication.
• It can be a standalone server.
HOW TO NODE?
• Delegate computationally
intensive tasks to lower-level
languages like C++.
• Make clusters (to combat
single-threading).
• Node errors will crash the
server. Gotta catch ‘em all.
EXPRESS.
• It is a Node Module.
• The most popular web
framework for Node.
• “Sinatra inspired”.
• Makes building web
application incredibly easy.
`REQ` AND `RES`
OBJECTS.
• `req` comes for the user.
• `res` is sent back to the user.
• I use it extensively for “API-
styled” web platform.
PASSPORTJS.
• Authentication API.
• Supports almost any kind of
authentication framework.
• FaceBook, Twitter, Google
OAuth modules already
available.
HOW TO USE IT?
• Documentation is abit skimpy
and untelling.
• Learn by example:
https://scotch.io/tutorials/easy-
node-authentication-setup-
and-local
SEQUELIZEJS.
• Object-Relational-Mapper
(ORM)
• Works with MySQL, Postgres
and others.
• Promise-styled. Very intuitive
and maintainable code.
• Support transactions.
BLUEBIRD.
• Very good performance.
• Prevents `callback hell` in
asynchronous coding.
• Makes code very readable.
• Parallelism.
WHY ARE PROMISES SO
GOOD?
Because it’s very intuitive and
readable.
Codes that solves a problem but
cannot be easily understood, is a
problem.
SOME ADVICES
• Don’t use modules that are not
well-maintained.
• Worry about performance, but
not too much.
IN THE MIDDLE
Use MongoDB/Couchbase + a lot of indexing
OR
SQL with many many joins
SQL with serialized/encoded arrays
THE OLD WAYS
• Joins are slow.
• Serializing can be problematic.
• Atomic updates impossible.
• Values cannot be used as selection criteria.
YOU CAN DO THIS AND IT IS
STILL PROBABLY FAST
You find yourself trying to do “joining”.
Are there any ORMs for
Mongo/Couchbase?
CHANGE IS THE ROOT OF ALL
PROBLEMS.
Will your data become more relational
than it is now?
http://www.sarahmei.com/blog/2013/11
/11/why-you-should-never-use-
mongodb/
POSTGRES JSON AND
HSTORE
• A field that can contain “array-
structured” data.
• Atomic operations: Key/values
can be searched for and
indexed.
• Fast.
• Best thing since NPM, and
beer.
A VERY FLEXIBLE
STRUCTURE
id name data
1 Mary { “country”: “Singapore”, “dataMeta”: { “following”: “299”, “followers”: “484” }}
2 Lucy { “country”: “France”}
3 Jane null
4 Tom {“dataMeta”: { “following”: “479” }}
5 Dick {“dataMeta”: { “following”: “12”, followers: “40”}}
PERFORMANCE
• Different sources will stake
different claims.
• Comparing apples with
oranges.
• They are all quite fast.
IT IS NOT PERFECT
• Only HSTORE supports atomic
updates, JSON does not.
• HSTORE does not support
nested structure.
• Postgres JSON is very new.
Library support is adequate
but not mature.
CONCLUSION ON PG
• It is a RDB that is very capable
of handling schemaless data.
• Don’t over-normalize your
data.
• Use relations and constraints
for critical portions of your
data.