Lessons from Rewriting Without Meteor

Sung Won Cho / @mikeswcho

November 14, 2016 at Meteor Sydney

Outline

  1. RemoteBase?
  2. Why?
  3. How?
  4. What Changed?

RemoteBase?

A directory of remote companies and jobs.

Why?

  • Mistakes in setup
  • Wrong tool for the job

1. Not enabling oplog tailing

Unless `OPLOG_URL` is provided, server polls the DB for diff

Turn off reactivity if not using realtime update.

companies.jsMeteor.publish('companies', function (query, limit) {
  check(query, Object);
  check(limit, Match.Optional(Number));

  query['hidden'] = {$ne: true};

  // {reactive: false}
  let option = {sort: {official: -1, name: 1}};

  if (limit) {
    option.limit = limit;
  }

  Counts.publish(this, 'companies-counter', Companies.find(query), {noReady: true});
  return Companies.find(query, option);
});

2. DB setup

  • No indexing
  • Running app and MongoDB on the same host

3. No horizontal scaling

  • Did not utilize all cores
  • Use cluster by arunoda

No need for real time updates

How?

1. Set up development environment

'webpack-react-redux-babel-autoprefixer-hmr-scss-modules-universal-auth-boilerplate'

2. Copy over React components

Mantra decouples behaviors from view layer

3. Write API

What Changed?

1. Server side rendering is trivial

  • No publication/subscription.
  • As easy as `React.renderToString(<App />);`

2. User management is less trivial

Sadly, no more `Meteor.loginWithTwitter()`.

3. Deployment is faster

No more meteor build

4. Flexible stack

Currently Go + node.js + Postgres + Mongo

Conclusion

  1. Choose the right tool
  2. Use Mantra to decouple view layers
  3. Set up properly or just use PaaS

End

Sung Won Cho