Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correct way of creating a realtime application with Cassandra

Right now I have a ec2 instance running Cassandra and a simple websocket server. I would like to know if this is the correct way to make a "real time" chat application. Is there anything I'm missing?

Client connects to websocket, inserts a message, the message is stored into database, and the message is then sent to users if the record to the database is successful.

const cassandra = require('cassandra-driver');
const client = new cassandra.Client({ contactPoints: ['127.0.0.1'], 
localDataCenter: 'datacenter1' });

const WebSocket = require('ws');
const wss = new WebSocket.Server({ port: 3000 });

wss.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {

   //Insert message into Cassandra DB
   //Send message to other users if record to database with a consistency 
      level of one is successful
   //Then send messages to users connected to the websocket in chatroom

});

Edit: I also can't seem to find any tutorials on something like this so if you have any links please share

like image 440
WHOATEMYNOODLES Avatar asked Sep 22 '19 01:09

WHOATEMYNOODLES


1 Answers

There is no simple answer to your question and it is not very clear what is about. 'if record in db is successful' is not an easy thing in context of distributed systems like Cassandra, because you can have many replicas of your data. It is always a tradeoff between data consistency and availability. First of all you need to understand the CAP theorem before using Cassandra.

I'm not sure that the chat app reuires strong consistency, but it will be good to have 2 or 3 replicas of data. In case of cassandra you can choose more suitable consistency level. I think for chat massages it can be ONE or ANY, in this case Csaandra will provide evantually consistency, but you will have more availability and performance in comparison with more 'strong'consistency levels.

like image 122
Mikhail Baksheev Avatar answered Oct 04 '22 15:10

Mikhail Baksheev