Created: 2011-07-13 04:50
Updated: 2014-06-01 11:56

Postoffice: Simple threaded messaging using Cassandra

Postoffice is a simple threaded messaging system on top of Cassandra meant to serve as a basic guide for using Cassandra from Java. The system can either be accessed using the Java API or via an HTTP interface that returns JSON and levarages Netty for performance.

The layout is as follows:

folders : {
  folder_id_1 : [conv_id_1, conv_id_2, conv_id_3, ...],
  folder_id_2 : [conv_id_1, conv_id_2, conv_id_3, ...],

conversations : {
  conv_id_1 : [msg1, msg2, msg3, ...],
  conv_id_2 : [msg1, msg2, msg3, ...],

The folder_id_X and conv_id_X values are built in a way that allows them to be multi-user and multi-folder.

The HTTP interface can be easily extended by adding URLs and their respective handlers. The handlers can then perform the needed operations and use Google GSON to create the response.

Interesting bits and pieces that one could add are hooks around request handlers that allow certain objects to be cached partially or fully. One should also be able to keep track of unread counts for respective folders.

Example Java calls:

String alice = "1501571";
String bob = "1501572";

String from = alice;
String to = bob;

  from, to, 
  "Postoffice project!", 
  "Hi " + to + ", I just wanted to tell you about Postoffice, a messaging system using Cassandra!"

Example HTTP requests:

Get first 10 messages in a the "inbox" folder for "1501572":


Create a new conversation:


Reply to an existing conversation given its id:


Cassandra schema:

create column family folders with column_type = 'Standard' and comparator = 'TimeUUIDType';
create column family conversations with column_type = 'Standard' and comparator = 'TimeUUIDType';

(C) 2011 Hisham Mardam-Bey

Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more