5

Recently, we started developing a chat feature for our app and since we are already using Parse SDK/Server, we decided to go with the Parse LiveQuery...

The thing is, there's no sufficient enough documentation on how to deploy a Parse LiveQuery server, on a separate one! We saw this: http://docs.parseplatform.org/parse-server/guide/#scalability but we didn't really figured out on how to proceed...

So we have a couple of questions:

What do we need to do, in order to create a scalable Parse LiveQuery Server? (preferably on Digital Ocean / Heroku)

How can it communicate, with our original Parse Server, where our MongoDB is stored?

Julien Kode
  • 5,010
  • 21
  • 36
Sotiris Kaniras
  • 520
  • 1
  • 12
  • 30
  • My precedent answer have solve your problem ? – Julien Kode May 23 '17 at 20:01
  • @JulienKode Yeah, I'm ok with that part of the development! Now I want to complete the deployment part and I have no idea about it... – Sotiris Kaniras May 23 '17 at 20:37
  • Yes I have... what I want now, is the Parse LiveQuery server, to communicate with my separate Parse server and its database – Sotiris Kaniras May 24 '17 at 11:56
  • Yes, but let me remind you that the database is on Parse Server A, and the Parse LiveQuery Server, is on Parse Server B! So how will the Parse LiveQuery server, (server B), get notified of the change in the db of server A? – Sotiris Kaniras May 24 '17 at 19:10
  • In you Parse Server B give the databaseUri of your database A: var api = new ParseServer({ databaseURI: 'mongodb://myMogoURL', – Julien Kode May 24 '17 at 20:10
  • That's great! So if I got it right, in order to make the Parse LiveQuery servers scalable, I need to deploy somewhere a redis-server, correct? If so, is it a good idea to install it on the server where my Parse Server is deployed, or should I do it on a separate one? – Sotiris Kaniras May 30 '17 at 17:48
  • It depends your charge I think, If you want to have a big architecture use redis-server, The 2 option are great – Julien Kode May 30 '17 at 18:05

2 Answers2

3

Here is our way to setup scalable Parse LiveQuery server on Heroku Because there is one and only 'web' process on Heroku, it will divide into two Heroku apps: Main and LiveQuery.

A: Main app - All features except for LiveQuery server

Step A1. Setup a Parse app on Heroku

Step A2. Add a Heroku Redis (free plan is enough for testing)

Step A3. Configure Parse app, add redisURL for liveQuery

var api = new ParseServer({
  ...
  liveQuery: {
    classNames: [...],
    redisURL: REDIS_URL_ON_MAIN
  },
  ...
});

B: LiveQuery app - A scalable LiveQuery server for Main app

Step B1. Steup another Parse app on Heroku

Step B2. Configure Parse app, DO NOT set liveQuery

var api = new ParseServer({
  appId: APP_ID_ON_LIVEQUERY,
  masterKey: MASTER_KEY_ON_LIVEQUERY,
  serverURL: SERVER_URL_ON_LIVEQUERY,
  databaseURI: // (Optional) Only warning even if leave it default
});

Step B3. Create LiveQuery server

var app = express();
app.use(PARSE_MOUNT_ON_LIVEQUERY, api);

var httpServer = require('http').createServer(app);
httpServer.listen(PORT_ON_LIVEQUERY, function() {
  /* Create HTTP server successfully */
});

ParseServer.createLiveQueryServer(httpServer, {
  redisURL: REDIS_URL_ON_MAIN // Redis URL from Mani app
});

C: Client side - Swift for example

Step C1. Init Client instance using

Client(server:applicationId:clientKey:)

let client = Client(server: SERVER_URL_ON_LIVEQUERY, 
                    applicationId: APP_ID_ON_LIVEQUERY, 
                    clientKey: nil)

Step C2. Subscribe for LiveQuery

let subscription = client.subscribe(query)
subscription.handle(Event.created, { query, object in
  /* Handle CREATE event */
})

In the end, we can scale web process in LiveQuery app on Heroku ^_^

Welcome any comments on my glist

ananfang
  • 566
  • 1
  • 8
  • 19
  • Thanks @ananfang. I'm in the process of setting this up. We use AWS so it's a little different. Trying to interpret this guide for that. Any suggestions? If I just go with Setup A, will LiveQueries work without explicitly doing `createLiveQueryServer`? – Zack Shapiro Aug 06 '18 at 19:02
  • @ZackShapiro If you want to use **only one** instance to handle parse server with live query, you can refer to: [parse-community/parse-server-example](https://github.com/parse-community/parse-server-example) – ananfang Aug 08 '18 at 01:25
1

In you Parse Server B give the databaseUri of your database A: var api = new ParseServer({ databaseURI: 'mongodb://myMogoURL',

Julien Kode
  • 5,010
  • 21
  • 36