I want my data out: streaming + observable + 
paging 
Christopher Batey 
@chbatey 
©2013 DataStax Confidential. Do not distribute without consent. 
1
Who am I? 
•Technical Evangelist for Apache Cassandra 
• Founder of Stubbed Cassandra 
• Help out Apache Cassandra users 
• Previous: Senior software engineer @ BSkyB
Cassandra is great because… 
• What was once hard is now easy! 
• More and more features that aren’t part of 
its core competency
Your favourite - OutOfMemory 
Application C Big Query
Your favourite - OutOfMemory 
Application C Big Query
Your favourite - OutOfMemory 
Uh oh, OutOfMemory 
Application C Big Query
Your favourite - OutOfMemory 
Uh oh, OutOfMemory 
Application C Big Query
Okay so 2 gb queries aren’t 
recommended?
Manual paging 
WEB 
Your Application 
DAO 
Lots of small queries 
Super C* 
Blocking 
Queue
Server side paging = awesome
Your favourite - OutOfMemory 
Uh oh, OutOfMemory 
Application C Big Query
Not so manual paging 
Your Application 
Super awesome paging query! 
C*
ResultSet + Observable = Awesome 
public Observable<CustomerEvent> getCustomerEventsObservable(String customerId) { 
BoundStatement boundStatement = getEventsForCustomer.bind(customerId); 
ListenableFuture<ResultSet> resultSetFuture = session.executeAsync(boundStatement); 
Observable<ResultSet> observable = 
Observable.from(resultSetFuture, Schedulers.io()); 
Observable<Row> rowObservable = observable.flatMapIterable(result -> result); 
return rowObservable.map(row -> new CustomerEvent( 
row.getString("customer_id"), 
row.getUUID("time"), 
row.getString("staff_id"), 
row.getString("store_type"), 
row.getString("event_type"), 
row.getMap("tags", String.class, String.class))); 
} 
p
ResultSet + Observable = Awesome 
Observable<CustomerEvent> chbatey = customerEventDao.getCustomerEventsObservable("chbatey"); 
chbatey.doOnCompleted(() -> { 
try { outputStream.close(); } catch (IOException e) { } 
}); 
chbatey.subscribe(event -> { 
try { outputStream.write(event.serialise()); } catch (IOException e) { } 
});
Manual paging 
WEB 
Your Application 
DAO 
Lots of small queries 
Super C* 
Blocking 
Queue
Thanks for listening 
@chbatey 
http://christopher-batey.blogspot.co.uk

Cassandra Summit EU 2014 Lightning talk - Paging (no animation)

  • 1.
    I want mydata out: streaming + observable + paging Christopher Batey @chbatey ©2013 DataStax Confidential. Do not distribute without consent. 1
  • 2.
    Who am I? •Technical Evangelist for Apache Cassandra • Founder of Stubbed Cassandra • Help out Apache Cassandra users • Previous: Senior software engineer @ BSkyB
  • 3.
    Cassandra is greatbecause… • What was once hard is now easy! • More and more features that aren’t part of its core competency
  • 4.
    Your favourite -OutOfMemory Application C Big Query
  • 5.
    Your favourite -OutOfMemory Application C Big Query
  • 6.
    Your favourite -OutOfMemory Uh oh, OutOfMemory Application C Big Query
  • 7.
    Your favourite -OutOfMemory Uh oh, OutOfMemory Application C Big Query
  • 8.
    Okay so 2gb queries aren’t recommended?
  • 9.
    Manual paging WEB Your Application DAO Lots of small queries Super C* Blocking Queue
  • 10.
  • 11.
    Your favourite -OutOfMemory Uh oh, OutOfMemory Application C Big Query
  • 12.
    Not so manualpaging Your Application Super awesome paging query! C*
  • 13.
    ResultSet + Observable= Awesome public Observable<CustomerEvent> getCustomerEventsObservable(String customerId) { BoundStatement boundStatement = getEventsForCustomer.bind(customerId); ListenableFuture<ResultSet> resultSetFuture = session.executeAsync(boundStatement); Observable<ResultSet> observable = Observable.from(resultSetFuture, Schedulers.io()); Observable<Row> rowObservable = observable.flatMapIterable(result -> result); return rowObservable.map(row -> new CustomerEvent( row.getString("customer_id"), row.getUUID("time"), row.getString("staff_id"), row.getString("store_type"), row.getString("event_type"), row.getMap("tags", String.class, String.class))); } p
  • 14.
    ResultSet + Observable= Awesome Observable<CustomerEvent> chbatey = customerEventDao.getCustomerEventsObservable("chbatey"); chbatey.doOnCompleted(() -> { try { outputStream.close(); } catch (IOException e) { } }); chbatey.subscribe(event -> { try { outputStream.write(event.serialise()); } catch (IOException e) { } });
  • 15.
    Manual paging WEB Your Application DAO Lots of small queries Super C* Blocking Queue
  • 16.
    Thanks for listening @chbatey http://christopher-batey.blogspot.co.uk