Reputation: 20872
I have a concept that I want to get peoples opinions on for running sessions in AWS with the redundancy of DynamoDB and the speed of Elasticache.
Good, bad, messy, to complex??
Upvotes: 6
Views: 5149
Reputation: 6517
To add to what jamieb said, here are some links:
If you are going to use ElastiCache, I suggest using their auto-discovery feature so you only have to worry about one memcache endpoint regardless of how many cache nodes there actually are.
If you are going to use DynamoDB, you should use the DynamoDB Session Handler provided by the AWS SDK for PHP. Here is a simple code sample for how to use the session handler:
<?php
// Load SDK via Composer autoloader
require 'vendor/autoload.php';
// Instantiate the SDK with your config
$aws = Aws\Common\Aws::factory('/path/to/config/file');
// Instantiate the DynamoDB client and register the session handler
$db = $aws->get('dynamodb');
$db->registerSessionHandler(array(
'table_name' => 'sessions',
'hash_key' => 'id',
));
// Use PHP sessions like normal
session_start();
$_SESSION['foo'] = 'bar';
session_commit();
Upvotes: 4
Reputation: 10033
No, it's not bad/complex--that's a pretty standard usage of memcache as a write-through cache of a persistent data store. However, it's a really expensive solution from monthly AWS billing perspective.
Have you benchmarked using just DynamoDB at all? It's an SSD-backed key-value store that ought to be plenty fast enough. I say "ought to" though, because I had issues with horrible latency when I attempted to do the same thing on it. We ended up moving purely to an ElasticCache solution and simply live with the possibility of node failure. But this was for an existing application that was shoe-horned onto AWS in a hurry and was using ridiculously large session objects. I haven't had time to revisit the idea.
Upvotes: 5