views:

160

answers:

1

Let's say I have N > 1 TCP-based, connection-oriented (read: not a website) services handling connections from end users in some load-balanced/sharing configuration.

These users do things that cause updates to one or more keys in the centralized Tokyo Tyrant datastore.

What do you recommend to push these changes to interested users connected to a different service instance running on the same private network (same colo.)?

User 1     Service 1      Tokyo Tyrant      Service 2           User 2
------     ---------      ------------      ---------           ------
  |            |               |                |                 |
  ------> do something         |                |                 |
  |            |       ---> put K 42            |                 |
  |            |               |     ----> Hey! K is now 42       |
  |            |               |                |          ---> K was updated

A few ideas:

Broadcast the changes on successful update of the datastore from Service N to all other services

User 1     Service 1      Tokyo Tyrant      LAN Broadcast       Service 2       User 2
------     ---------      ------------      -------------       ---------       ------
  |            |               |                |                 |                |
  ------> do something         |                |                 |                |
  |            |       ---> put K 42            |                 |                |
  |            |       -----------------> Hey! K is now 42        |                |
  |            |               |                |         --> Hey! K is now 42     |
  |            |               |                |                 |         ---> K was updated

Store which Service each interested user is logged onto and send those services a message which is then relayed to the interested user; I suppose this is how IRC server-server connections work (need to research that).

User 1     Service 1      Tokyo Tyrant      Service 2           User 2
------     ---------      ------------      ---------           ------
  |            |               |                |                 |
  ------> do something         |                |                 |
  |            |       ---> put K 42            |                 |
  |            |       ---> who cares?          |                 |
  |            | <--- User 2 on Service 2       |                 |
  --------------------------------------> Hey! K is now 42        |
  |            |               |                |          ---> K was updated

Run a message broker (e.g. RabbitMQ); have each Service X subscribe to a queue on behalf of the interested users; post to it upon successful "put"s

User 1     Service 1      Tokyo Tyrant      RabbitMQ           Service 2    User 2
------     ---------      ------------      --------           ---------    ------
  |            |               |                | <--- subscribe --|         |
  ------> do something         |                |                  |         |
  |            |       ---> put K 42            |                  |         |
  |            | ------------------- post msg -->                  |         |
  |            |               |                |----- notify ---->|         |
  |            |               |                |                  |  ---> K was updated

Yet another idea is to pretend to be a replication slave and connect to the master.

In general, I'm looking for a way to get "change notifications" as found in CouchDB but for Tokyo Tyrant. The idea is more general however.

If you suggest just using a message broker with persistent queues instead of a datastore like Tokyo Tyrant, please explain how I might hook into such to allow for validations, etc. I am not intimate yet with such.

+1  A: 

My recommendation (and what I use) is the message broker approach. RabbitMQ keeps track on services (un)subscribing to different queues and you can use fanout exchanges.

Also, Tokyo Cabinet has a log (in a weird format though) which you can use to get the updates and push them to a queue. I only tried using a cron but I think it can be possible to get it in real time using a socket.

Mihai A