{"action":"created","issue":{"url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/58","labels_url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/58/comments","events_url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/58/events","html_url":"https://github.com/ReactiveCouchbase/ReactiveCouchbase-core/issues/58","id":58927143,"number":58,"title":"Couchbase as an Idempotent Repository","user":{"login":"behrad","id":2151889,"avatar_url":"https://avatars.githubusercontent.com/u/2151889?v=3","gravatar_id":"","url":"https://api.github.com/users/behrad","html_url":"https://github.com/behrad","followers_url":"https://api.github.com/users/behrad/followers","following_url":"https://api.github.com/users/behrad/following{/other_user}","gists_url":"https://api.github.com/users/behrad/gists{/gist_id}","starred_url":"https://api.github.com/users/behrad/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/behrad/subscriptions","organizations_url":"https://api.github.com/users/behrad/orgs","repos_url":"https://api.github.com/users/behrad/repos","events_url":"https://api.github.com/users/behrad/events{/privacy}","received_events_url":"https://api.github.com/users/behrad/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2015-02-25T16:25:22Z","updated_at":"2015-02-26T09:28:38Z","closed_at":null,"body":"I want to implement an Idempotent Repository on Couchbase with three synchronous add, contains, remove operations, which will be called concurrently in a very high rate (5000 calls/sec each)\r\n\r\nmy very simple implementation is as below:\r\n```scala\r\n//Remove Op\r\nval res = Await.result( bucket.delete( key ), 1 second )\r\n\r\n// Contains check\r\nval res = Await.result( bucket.get[String]( key ), 1 second )\r\nres.exists( _ => true )\r\n\r\n// Add operation\r\nval res = Await.result( bucket.add( key, System.currentTimeMillis, CouchbaseExpirationTiming_byDuration( expiry ) ), 1 second )\r\nres.isSuccess\r\n```\r\n\r\nhowever this is not scalable and my operations time out under load.\r\nHow can I achieve better implementation? can stream methods help me with sync operations needed above?"},"comment":{"url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/comments/76146824","html_url":"https://github.com/ReactiveCouchbase/ReactiveCouchbase-core/issues/58#issuecomment-76146824","issue_url":"https://api.github.com/repos/ReactiveCouchbase/ReactiveCouchbase-core/issues/58","id":76146824,"user":{"login":"chenbekor","id":1867481,"avatar_url":"https://avatars.githubusercontent.com/u/1867481?v=3","gravatar_id":"","url":"https://api.github.com/users/chenbekor","html_url":"https://github.com/chenbekor","followers_url":"https://api.github.com/users/chenbekor/followers","following_url":"https://api.github.com/users/chenbekor/following{/other_user}","gists_url":"https://api.github.com/users/chenbekor/gists{/gist_id}","starred_url":"https://api.github.com/users/chenbekor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chenbekor/subscriptions","organizations_url":"https://api.github.com/users/chenbekor/orgs","repos_url":"https://api.github.com/users/chenbekor/repos","events_url":"https://api.github.com/users/chenbekor/events{/privacy}","received_events_url":"https://api.github.com/users/chenbekor/received_events","type":"User","site_admin":false},"created_at":"2015-02-26T09:28:38Z","updated_at":"2015-02-26T09:28:38Z","body":"I think that Mathiieu's code is always a real educational stuff - again Mathieu thank you for all that you are doing here.\r\n\r\n@behrad here is my opinion in terms of scalable solution that answers your requirement.\r\n\r\nWhat I would do here is wrap the couch related functionality in a separate micro service. I would expose the service via a REST API (or more performant protocols *only if* a bottleneck is identified)\r\n\r\nNext, I would put a load balancer in front of this micro service. If you are running on AWS I would recommend using ELB. We  see great results with that approach.\r\n\r\nNow - your micro service can scale in / out to handle thousands of concurrent requests.\r\n\r\nTo be more pragmatic I would recommend play framework which has great integration with reactive couchbase thanks to Mathieu. This will allow you to utilize the async API and the non-blocking nature of Play while retaining full synchronous operation from a REST API standpoint.\r\n\r\nSo internally - the service is async/non blocking but externally you provide a synchronous API which is exactly what you need for your use case. You can now call the REST API from your other parts (I guess the Camel plugin) and block on the micro service callback.\r\n\r\nneedless to say - play framework can be replaced by spray or finagle or what have you.\r\n\r\nCouchbase is rarely a bottleneck from our experience.\r\n"}}