Nodejs connect to AWS ElasticCache replication group - node.js

I have a Redis replication group where I have 1 master and 2 slave nodes. Slave nodes are read only. I am using node_redis to connect to Redis endpoint.
Now I want my application to connect to only slave nodes for any read query and only write query should go to master node. Do I have to make any changes in my application to connect or I can connect to master node and elastic cache will automatically redirect read queries to slave nodes?

Point the 'read queries' to the 'endpoint' of the slave node if used for non-critical purposes.
Another point to note is that data in Slave node 'may' be stale
Keep in mind that primary node can also be used for 'read'

Elasticcache does the load balancing of read queries

Related

Splitting read & write to redis with nodejs

I have setup redis on three seperate instances and have configured them in such a way that 1 instance is a master and 2 are replicas of master. I have used sentinels to make sure there is high availability of the setup. I have a nodejs application which needs to use the redis. How do i achieve the read and write splitting in my application as incase my redis master goes down one of my read replica becomes the master and the writes need to go to it.
As far has I know, ioredis is the only node redis client that supports sentinels.
"ioredis guarantees that the node you connected to is always a master even after a failover. When a failover happens, instead of trying to reconnect to the failed node (which will be demoted to slave when it's available again), ioredis will ask sentinels for the new master node and connect to it. All commands sent during the failover are queued and will be executed when the new connection is established so that none of the commands will be lost."

Mongo Db Replication error when Seconday node is down

I have a problem in mongodb replication .
Whenever my replica server is down (which is secondary node). Then I can't read from master db (and I guess it should not happen, because master database is up and running ).
I have two micro services ....one is calling only the master db in node js like ----
Mongo.connect(masterurl)
If I hit any api in backend that is querying the database, I get the error
not master or slave=false
And on the master db it shows ..connection refused to ip:port
But when the replica db is up then there is no error .
Master and replica are on different ip .
Thanks
If you have a two-node replica set, and one of the nodes is unavailable, the replica set does not have a primary. In order for a primary to exist in the RS, the majority of nodes must be available and communicating (so that they can elect the primary).
Then I can't read from master db (and i guess it should not happen , bacause master db is up and running ).
The "master db" is not a MongoDB concept, so this statement is meaningless in the context of MongoDB.
If you wish to run MongoDB in resource constrained environments, consider a PSA setup which comes with reduced redundancy and fault tolerance compared to PSS.

node js Master Slave replication with read and write queries split up

My application runs on node js and using PostgreSQL(pg-promise) for the database connection. I want that all write queries should go to master instances of DB and read queries to slave instance. I have set up the server configuration prostgresql.conf and pg_hba.conf files.
Now,how will the application will get to know that read queries going to slave and write to the master. Is there any library we have to install.
What you need is pgpool-II - http://www.pgpool.net/mediawiki/index.php/Main_Page
It is a multi-purpose tool, it can not only replicate your master db to slave DBs but will do load balancing for you. You have to just connect to your pgpool server, it will balance your write/read queries accordingly.

Connecting to both master and slave in a replicated Redis cluster

I'm setting up a simple 1 Master - N Slaves Redis cluster (low write round, high read count). How to set this up is well documented on the Redis website, however, there is no information (or I missed it) about how the clients (Node.js servers in my case) handle the cluster. Do my servers need to have 2 Redis connections opened: one for the Master (writes) and one towards a Slave load-balancer for reads? Does the Redis driver handle this automatically and send reads to slaves and writes to the Master?
The only approach I found was using thunk-redis library. This library supports connecting to Redis master-slave without having a cluster configured or using a sentinel.
You just simply add multiple IP addresses to the client:
const client = redis.createClient(['127.0.0.1:6379', '127.0.0.1:6380'], {onlyMaster: false});
You don't need to specifically connect to particular instance, every instance in redis cluster has information of cluster. So even if you connect to one master, your client would to be connect to any instance in the cluster. So if you try to update a key present in different master(other than the one you connected), redis client takes care of it by using the redirection provided by the server.
To answer your second question, you can enable reads from slave by READONLY command

How to handle read/write request in cassandra

I have 5 node cluster with 2 Cassandra,2 solr and 1 hadoop on EC2 with DSE4.5.
My requirement is I dont want to hard code node IP address while requesting for Reading/writing from Cluster. I have to develop web service, thru which requester can send read/write request to my cluster and web service has to determine following
1) route read request to appropriate node.
2) route write request to appropriate node.
If there is any write request then it should direct to Cassandra node on basis of keyspace and replication factor. if it is a read request then request should route to Solr node (as I done indexing on solr) and if there is any analytic query then request should route to hadoop.
And if any node goes down in that case response will not affect.
Apart from dedicated request, is there any way to request a cluster ?
by dedicated mean giving specific IP address for read and write.
Is any method or algorithm exist in DSE? or Is there any tool available in for this?
The Java driver should take care of all of that for you:
http://www.datastax.com/documentation/developer/java-driver/2.0/common/drivers/introduction/introArchOverview_c.html
For example:
Nodes discovery: the driver automatically discovers and uses all nodes of the Cassandra cluster, including newly bootstrapped ones
Configurable load balancing: the driver allows for custom routing and load balancing of queries to Cassandra nodes. Out of the box, round robin is provided with optional data-center awareness (only nodes from the local data-center are queried (and have connections maintained to)) and optional token awareness (that is, the ability to prefer a replica for the query as coordinator).
Transparent failover: if Cassandra nodes fail or become unreachable, the driver automatically and transparently tries other nodes and schedules reconnection to the dead nodes in the background.
On the Solr query side, you can use the SolrJ load balancer, but you have to hard-wire the list of nodes to be used as coordinator nodes, but SolrJ will round robin for you.

Resources