I have a node js app that runs on elastic beanstalk server. The server is configured to auto-scale when the load gets high. I was thinking, how can I share variables between all the instances? One way would be to save them to dynamodb, but isn't there a simpler way?
1 Answers
What do you mean by "variables" exactly? Session data? Global application data?
In general, when an application is distributed across multiple servers on AWS you want to share data via a database (RDS or DynamoDB) or a cache (ElastiCache), and you want to share files via S3.
You can turn on sticky sessions on the load balancer so that all requests from an individual user will go to a single server. This prevents the user from suddenly becoming logged-out or losing data when the application scales out, without having to ship that user's data to the new server. If you have long-running user sessions then sticky sessions may prevent optimal load balancing across servers.
If you want to share sessions across servers, to prevent the need for sticky sessions, or to simply handle scale-in events more gracefully, you can store user sessions in Redis (ElastiCache).
-
I meant global application data, the type of things I would normally store in a variable, not user sessions. – Mister_L May 12 '16 at 22:04
-
would you still recommend ElastiCache for this? – Mister_L May 12 '16 at 22:16
-
I would highly suggest using an RDS instance, or an S3 bucket (using the AWS_SDK), if you intend on the shared data including anything more than a handful of small variables. Ultimately, just take a long hard look at ElastiCache, as +Mark_B suggests. – Tony Chiboucas May 13 '16 at 01:30