Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Cisco: Application clustering with Couchbase – Couchbase Connect 2016

307 views

Published on

NoSQL is all about doing more, with less. This session will provide a deep dive into techniques for building an application clustering framework, backed by Couchbase. It explores how to roll your own functionality for discovery, load distribution, leader election, and more with Couchbase and simple application libraries.

Published in: Software

Cisco: Application clustering with Couchbase – Couchbase Connect 2016

  1. 1. Clint Ricker Couchbase Application Clustering
  2. 2. • Solutions Architect, Office of the CTO • SP Video Me
  3. 3. • Shipping Couchbase in service provider grade software since 2012 • Running in mission critical, very large scale on-prem and AAS offerings around the world • Datasets of billions of records Cisco / Couchbase
  4. 4. • Creating a clustered application glued together by Couchbase • Use Couchbase / lightweight code snippets instead of common datacenter technologies • Replacing Zookeeper, Eureka, Consul, Rabbit/HornetMQ, etc… What
  5. 5. What AppInstance AppInstance AppInstance Couchbase AppInstance AppInstance AppInstance Couchbase Shared Storage Dependent Databases Zookeeper Consul RabbitMQ Load Balancer Load Balancer
  6. 6. • Complexity kills • Lower machine count • Organizational needs • Application needs • Love of roll your own • Very minimal feature set Why
  7. 7. • More application code to maintain • Schema changes are difficult • Existing platform stack • Less sensitivity to deployment footprint • Very minimal feature set Why not
  8. 8. Global Distributed Lock
  9. 9. Global Distributed Lock • Used to ensure certain activities are globally serialized • Typically provided by Consul / Zookeeper / etc
  10. 10. Global Distributed Lock
  11. 11. Global Distributed Lock uint64_t CBGetLock(char *lockKey, int objectLockTimeout) { if (status == CBSTATUS_SUCCESS) { for (i = 0; i < retries; i++) { status = CBObjGet(buf, &cas, lockKey,objectLockTimeout); if (status >= 0) { return cas; } } } return CBSTATUS_FAILURE; }
  12. 12. Leader Election
  13. 13. Leader Election • Used to have a dynamically dedicated master instance for ongoing activity • Common for frequent maintenance needs • Typically provided by Consul, Zookeeper, etc…
  14. 14. Leader Election
  15. 15. Leader Election uint64_t CBElectMasterPrivate(char *masterKey, int ttl, uint64_t masterKeyCas) { if (masterKeyCas > 0) { status = CBObjReplace(masterKey, "master", masterKeyCas, ttl); } else { status = CBObjSet(masterKey, "master", masterKeyCas, ttl); } if (status == CBSTATUS_SUCCESS) { for (i = 0; i < retries; i++) { status = CBObjGet(buf, &cas, masterKey, NOLOCK); if (status >= 0) { return cas; } } CBObjDeleteCas(masterKey, cas); return CBSTATUS_FAILURE; } return CBSTATUS_FAILURE; }
  16. 16. Discovery Service
  17. 17. Discovery Service • Used to discover endpoints for specific services or the total set of nodes in the cluster • Supports basic load balancing and health check • Often provided by Consul, Eureka, DNS, etc…
  18. 18. Advertise
  19. 19. <NodeList> <Node> <NodeName>appInstance1</NodeName> <Updated>2016-10-24T12:23:42Z</Updated> <Address>172.31.31.15:80</Address> </Node> </NodeList> <NodeList> <Node> <NodeName>appInstance2</NodeName> <Updated>2016-10-24T12:23:41Z</Updated> <Address>172.17.126.2:80</Address> </Node> </NodeList> Example
  20. 20. Discovery
  21. 21. Discovery Couchbase App2 Service Instance App2 Service Instance App2 Service Instance App1 Service Instance Advertise “foo”, “instance ip address” Lookup “foo”, choose instance Send request to address of selected instance
  22. 22. Shared Queues
  23. 23. Shared Queues • Create shared queues that are polled by set of nodes • Typically provided by HornetQ, RabbitMQ, etc…
  24. 24. Shared Queue Add
  25. 25. Shared Queue Read
  26. 26. Transactions
  27. 27. Transactions • Create a generic globally shared transaction system with rollback • Typically provided by HornetQ, RabbitMQ, etc…
  28. 28. Transactions App1 Service InstanceIncoming request App2 Service Instance App2 Service Instance App1 Service Instance App1 Service Instance L B Service request w/callback URL Service request w/callback URL Callback Callback
  29. 29. If transaction failed or timed out 1 2 Create Transaction Transaction State Record w/state=active and time=currentTime Transaction Log Record 1 2 4 Close Transaction Delete Transaction State Record Delete Transaction Log 1 2 3 Rollback Either synchronously with failure or discovered through query of transaction state records Pull transaction log Iterate through transaction log in reverse Undo each activity 1 2 3 Transactions Update Transaction state record with state=active and time=currentTime Append Activity to Transaction Log Record 1 2 Execute Activity

×