Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.io compatibility with cube.js #221

Closed
rizvanhaider opened this issue Oct 1, 2019 · 10 comments
Closed

Socket.io compatibility with cube.js #221

rizvanhaider opened this issue Oct 1, 2019 · 10 comments
Labels
enhancement New feature proposal

Comments

@rizvanhaider
Copy link

Is there any way to create the real-time charts with cubejs? compatibility of Socket.io or real-time data with cubejs will be a great feature because most analytics needs real-time data.

@nicodds
Copy link

nicodds commented Oct 1, 2019

I was evaluating the same thing. I would give my 2 cents on the topic suggesting the use of cossbar's Autobahn, since it is a well performing and multi-{platform|language} alternative to socket.io

@paveltiunov
Copy link
Member

@rizvanhaider @nicodds Hey Rizwan and Domenico! Thanks for posting this! As it's ongoing conversation I'll put some more context info here.

In general most of databases supported by Cube.js are retroactive. It means databases usually don't support any push/subscription mechanism to listen for changes of underlying data. So to implement some sort of push/subscription behavior for clients cube.js backend should constantly poll databases for changes. Refresh key concept pretty well suited for that: https://cube.dev/docs/caching#in-memory-cache-refresh-keys.

So in order to implement it I think we need to decide on how should we define polling interval: should it be defined by client or server? Per cube or global?

@rizvanhaider @nicodds Would love to hear more about your socket push/subscriptions use cases to better understand what type of configuration it requires.

@nicodds
Copy link

nicodds commented Oct 2, 2019

Ciao @paveltiunov, thank you for the reply! My initial idea was to evaluate the possibility of integrating some sort of pub/sub component in cube.js backend. This integration may be used in two different ways:

  1. notify subscribed clients of a change in a particular dataset, forcing reload;
    or
  2. send directly the new data (or an aggregated form) to the subscribed clients.

@rizvanhaider
Copy link
Author

@paveltiunov Thanks Pavel for your detailed response.
If we consider the use case of website analytics and we want to see the real time users.

Consider our own implementation of tracking users on our website and every new user make an increment in database (table => cube => dimension/measure), so If we want to see the real time figures via our cubejs api I think we need to implement it on specific cube and on specific measure/dimension. Also it should be defined by server so client should know it via subscription.

@paveltiunov
Copy link
Member

@nicodds @rizvanhaider Cool! What DB do you use?

@nicodds
Copy link

nicodds commented Oct 3, 2019

Actually I use an custom hybrid solution built on a Bokeh (python) application with data read both from a sqlite file (pre-aggreations) and BigQuery. Updates are received by the application via Google Pub/Sub and sent via web sockets to the clients. Unfortunately, this solution is hard to maintain (Bokeh, although an interesting project, has a complex approach to build an application) and difficult to scale.

@paveltiunov
Copy link
Member

@nicodds Got it! Do you plan to use external rollups https://cube.dev/docs/pre-aggregations#external-rollup? If so which DB?

@paveltiunov paveltiunov added the enhancement New feature proposal label Oct 5, 2019
@rizvanhaider
Copy link
Author

@nicodds @rizvanhaider Cool! What DB do you use?

currently I am using MySQL.

@paveltiunov
Copy link
Member

@rizvanhaider @nicodds Hey Guys! We released sockets support for preview. In order to use it just enable it on backend using env variable:

CUBEJS_WEB_SOCKETS=true

On client side we added WebSocketTransport which can be used as:

import cubejs from '@cubejs-client/core';
import WebSocketTransport from '@cubejs-client/ws-transport';

const cubejsApi = cubejs({
  transport: new WebSocketTransport({ authentication: CUBEJS_TOKEN, apiUrl: 'ws://localhost:4000/' })
})

We provided just simple reference implementation using low level ws api. There's SubscriptionServer class which can be used to build integrations with other socket libraries and frameworks like Socket.io or Serverless sockets: https://github.com/cube-js/cube.js/blob/master/packages/cubejs-api-gateway/SubscriptionServer.js.

We're open to various socket transport contributions and if you feel you need particular socket transport we can guide you on how to build it.

Could you please try it and let me know if it's helpful?

@nicodds
Copy link

nicodds commented Oct 22, 2019

That is super-cool! I'll give it a try ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature proposal
Projects
None yet
Development

No branches or pull requests

3 participants