Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building a Scalable Event Service with Cassandra

Building a Scalable Event Service with Cassandra

DataStax Tech Days - London - 30 September 2014

Tareq Abedrabbo

September 30, 2014
Tweet

More Decks by Tareq Abedrabbo

Other Decks in Programming

Transcript

  1. About Us • CTO at Open Credo • We are

    a software consultancy and delivery company • Open source, NoSQL/Big Data, cloud • DataStax Solutions Partner
  2. Agenda • Project background • The event service • API

    • Architecture • Implementation • Future improvements and lessons learnt
  3. • Large retail organisation • Decoupled micro services architecture •

    Java-based, event-driven platform • Cassandra, Cloud Foundry, RabbitMQ
  4. • Capture platform and business events • Trigger downstream processes

    asynchronously • Customisation standard processes in a non- intrusive way • Analytics • System testing
  5. • Simplicity (yes, really!) • Decouple API and implementation (contract-first)

    • Scalability and fault-tolerance • Flexibility in the implementation • Ability to evolve while minimising changes
  6. • Store an event • POST /api/events/ • Read an

    event • GET /api/events/{eventId}
  7. { "type" : "DEMOENTITY.DEMOPROCESS.DEMOTASK", "source" : "demoapp1:2.5:981a24b3-2860-40ba-90d4-c47ef1a70abe", "clientTimestamp" : 1401895567594,

    "serverTimestamp" : 1401895568616, "platformContext" : { "id" : "demoapp1", "version" : "2.5" }, "businessContext" : { "channel" : "WEB", }, "payload" : { "message" : "foo", "anInteger" : 33, "bool" : false } }
  8. • Query events • GET /api/events?{queryString} • {queryString} can consist

    of the following fields: • start, end, startOffset, limit, tag, type, order
  9. { "count" : 1, "continuation" : "http://event-service-location/api/events?continueFrom=9f00e9d0- ebfc-11e3-81c5-09597eb bf2cb&end=1401965827000&limit=1", "events"

    : [ { "type" : "DEMOENTITY.DEMOPROCESS.DEMOTASK", "source" : "demoapp1:2.5:981a24b3-2860-40ba-90d4-c47ef1a70abe", "clientTimestamp" : 1401895567594, "serverTimestamp" : 1401895568616, "platformContext" : { "id" : "demoapp1", "version" : "2.5" }, "businessContext" : { }, "payload" : { }, “self" : ”http://event-service-location/api/events/8d4ce680- ebfc-11e3-81c5-09597ebbf2cb" } ] }
  10. Anatomy of an Event public class Event { ! private

    final UUID id; private final EventType type; private final String source; private final Date clientTimestamp; private final Date serverTimestamp; private final Map<String, Object> platformContext; private final Map<String, Object> businessContext; private final Map<String, Object> payload; private final List<String> tags; }
  11. Primary Event Store create table events (id timeuuid primary key,

    source text, type text, cts timestamp, sts timestamp, bct map<text, text>, bcv map<text, blob>, pct map<text, text>, pcv map<text, blob>, plt map<text, text>, plv map<text, blob>); Events are simply keyed by id
  12. Indices create table events_by_time_asc (tbucket text, eventid timeuuid, primary key

    (tbucket, eventid)) with clustering order by (eventid asc); create table events_by_time_desc (tbucket text, eventid timeuuid, primary key (tbucket, eventid)) with clustering order by (eventid desc); Ascending and descending time buckets for each query type
  13. Future improvements • User Defined Types • DataStax SLOR integration

    • Spark integration • Testing with Stubbed Cassandra