Couchbase SDK and Moxi Client - couchbase

I am new to Couchbase and trying to understand why we need a Client side proxy like Moxi if using a Couchbase PHP SDK.
As per my understanding the proxying of client requests to right server is done by the Client SDK which maintains the vBucket map of all keys.
Why in case of a web application using PHP SDK and Couchbase, we need an additional Moxi client?

They are for two different things.
Moxi is for when you want to use a standard memcached library as MOXI will proxy memcached calls to the Couchbase cluster and use Couchbase buckets. Your code will not know it is talking to a persistent database in the background. Using moxi with Couchbase buckets will give you some of the benefits of Couchbase, like High Availability, easy scalability and performance Couchbase is known for, but you can use any old off the shelf memcached library. Just know that because of adhering to memcached, moxi is limited to that functionality from an application perspective.
In my opinion, moxi should be used to bridge the gap between people on memcached and using the full SDKs and is not meant to be a final destination, though some people have been on it for years.
Using the Couchbase PHP SDK on the other hand gives you the full suite functionality that Couchbase can offer and you do not need MOXI at all.
In summary, if you are in a spot to use the Couchbase SDK, do that. You will get more functionality, performance, etc. from it. Moxi is for those that are already have memcached, but want to step up to a clustered high performance cache and not change their code.

Related

Couchbase Sync Gateway business logic

I'm currently working on an architecture with an offline mobile client and a database server.
I was thinking about using the sync-gateway component from couchbase, hence, couchbase as a server db and pouchdb as a client db.
The business logic is quite complex, though and as far as I understand, synchronization filtering, data validation and authorization is made through the gateway configuration.
Is this a good idea or couchbase synchronization capabilities are preferred for simpler logics and I should stick to a more Spring Rest API and fill the local indexDB manually.
Couchbase Sync Gateway is used in very large enterprise grade deployments of varying complexity and scale so that shouldn't be an issue. The decision you would need to make is whether you need sync or you are looking for a simple request-response approach (that's better suited for connected environments). FWIW, Sync Gateway also supports a REST interface - so you can use indexedDB requesting data via the REST interface as well.
You mention offline mobile client so why are you not using couchbase lite as the embedded database? Is this a PWA? The synchronization protocol between Couchbase lite and Sync Gateway is more performant and advanced compared to the couchDB based approach used between the likes of PouchDB and Sync Gateway.

unable to sync pouchDB with couchBase Sync Gateway

I am trying to sync pouchDB with couchBase through Sync Gateway, but i just get data added by pouchDB, not initial data added to couchBase. For example there is 750 docs in couchBase but none of them synced to the pouchDB. Also http://localhost:4985/_admin/db/db not showing couchBase docs too.
The problem is with adding data to Couchbase Server directly. Couchbase Mobile currently requires extra metadata in order to deal with replication and conflict resolution. This isn't handled by the Server SDKs.
The recommended approach is to do all database writes through Sync Gateway.
To simplify use with PHP, you may want to use a Swagger PHP client. (You can see an example of using clients autogenerated by Swagger in this post. The example use Javascript and Node.js, but the principles are the same.)
You can read from Couchbase Server directly if you want (to do a N1QL query, for example).
Another option is to use "bucket shadowing". This is trickier, and is likely to get deprecated at some point. I only list it for completeness.

Ejabberd Redis + MySql database combination

I am newbie to the Ejabberd so I am still exploring all the possibilities and possible setups for chat server.
From the documentation I have seen that Ejabberd supports Redis database for transient data, user session I suppose...
I was wondering has anyone had any experience using Redis for storing transient data and then MySql for the rest of the data? Will this setup be beneficial comparing to Mnesia + MySql one? Maybe Redis + Riak is even better setup?
Just looking for some general opinions since I am a newcomer in this area...
Full disclosure: I work for Basho, the maintainers of Riak, so I have a clear preference here.
Looking at the source of Ejabberd, I see it's written in Erlang as well, which is optimized as a distributed system. Their architecture diagram specifically shows Riak as a NoSQL backend. Redis is often paired with Riak due to its simple retrieval and key/value design. If scale is a concern on the transient side as well, you could use Riak's in-memory backend alongside the disk-based backend for durable data (more on backends here).
Riak is designed for scaling, so if you anticipate growth beyond a single server's worth of CPU, memory or storage, then it's perfect. If you do not anticipate this growth, then Riak may be overkill. For more on when to use it, read this.

Running couchbase on AWS under auto scaling

I want to run couchbase on AWS EC2. Since my traffic is cyclic in nature, can I run Couchbase under auto-scaling. Since there are a lot of steps required to add/remove a node, I was wondering if this is the right approach. Has anybody tried it ?
It has been done before. Here is a high level list of the things you'd have to do:
Define which Couchbase metrics you need to use to base your scaling considerations on
Create a script to get those metrics from Couchbase and put them into Cloudwatch using Couchbase Rest API or CLI.
Create an AMI with Couchbase installed and OS configured.
Script the addition of one or more new nodes (using Couchbase Rest API or CLI), plus a rebalance, as a response to Auto-scaling
Script the removal and rebalance of nodes (using Couchbase Rest API or CLI), as a response to contraction in auto-scaling.
With you reliying on rebalances here, you will have to watch how long your rebalances take and perhaps tune your cluster (e.g. move more vBuckets at once and other settings) and usage of Couchbase for faster rebalances (e.g. if you have large views, they can have an effect on rebalances). Normally rebalances are meant to be a background process and take as long as they take, but that may not be appropriate in this particular use. Only you can answer that.

How does a LAMP developer get started using a Redis/Node.js Solution?

I come from the cliche land of PHP and MySQL on Dreamhost. BUT! I am also a javascript jenie and I've been dying to get on the Node.js train. In my reading I've discovered inadvertently a NoSQL solution called Redis!
With my shared web host and limited server experience (I know how to install Linux on one of my old dell's and do some basic server admin) how can I get started using Redis and Node.js? and the next best question is -- what does one even use Redis for? What situation would Redis be better suited than MySQL? And does Node.js remove the necessity for Apache? If so why do developers recommend using NGINX server?
Lots of questions but there doesnt seem to be a solid source out there with this info all in one place!
Thanks again for your guidance and feedback!
NoSQL is just an inadequate buzz word.
I'll attempt to answer the latter part of the question.
Redis is a key-value store database system. Speed is its primary objective, so most of its use comes from event driven implementations (as it goes over in its reddit tutorial).
It excels at areas like logging, message transactions, and other reactive processes.
Node.js on the other hand is mainly for independent HTTP transactions. It is basically used to serve content (much like a web server, but Node.js really wouldn't be necessarily public facing) very fast which makes it useful for backend business logic applications.
For example, having a C program calculate stock values and having Node.js serve the content for another internal application to retrieve or using Node.js to serve a web page one is developing so one's coworkers can view it internally.
It really excels as a middleman between applications.
Redis
Redis is an in-memory datastore : All your data are stored in the memory meaning that a huge database means huge memory usage, but with really fast access and lookup.
It is also a key-value store : You don't have any realtionships, or queries to retrieve your data. You can only set a key value pair, and retreive it by its id. (Redis also provides useful types such as sets and hashes).
These particularities makes Redis really well suited for storing sessions in a web application, creating indexes on a database, handling real-time data like analytics.
So if you need something that will "replace" MySQL for storing your basic application models I suggest you try something like MongoDB, Riak or CouchDB that are document store.
Document stores manages your data as something analogous to JSON objects (I know it's a huge shortcut).
Read this article if you want to know more about popular nosql databases.
Node.js
Node.js provides asynchrous I/O for the V8 JavaScript engine.
When you run a node server, it listens on a port on your machine (e.g. 3000). It does not do any sort of Domain name resolution and Virtual Host handling so you have to use a http server with a proxy such as Apache or nginx.
Choosing over nginx in production is a matter of performance, and I find it easier to use. But I suggest you use the one you're the most comfortable with.
To get started with it just install them and start playing with it. HowToNode
You can get a free plan from https://redistogo.com/ - it is a hosted redis database instance.
Quick intro to redis data types and basic commands is available here - http://redis.io/topics/data-types-intro.
A good comparison of when to use what is here - http://playbook.thoughtbot.com/choosing-platforms/databases/