Redis is being used in multiple ways to support the microservices architecture at eharmony. Redis is used as an authentication store for access and refresh tokens. It is also used as the primary data store for user profiles, activities, and badges. Redis hashes and sorted sets enable fast retrieval and updates of user data and security anomalies. Redis pub/sub is utilized for dynamic configuration updates. Sentinel provides high availability. Redis is helping to improve performance and scalability of the microservices.
3. • Our comprehensive & revealing Relationship Questionnaire
• 29 Dimensions® of Compatibility
• 15+ million matches per day globally
(20+ billion since inception)
• 100+ thousand photos uploaded per day
• 1+ million communications per day
Who is eharmony?
SUPERCHARGE MICROSERVICES WITH REDIS
8. A microservice is a single self-contained unit which, together with
many others, makes up a large application.
Microservices
SUPERCHARGE MICROSERVICES WITH REDIS
9. Benefits Of Microservices
Developer Independence
Small teams work in parallel and can iterate faster.
Eliminates any long-term commitment to a
technology stack.
Isolation and resilience
If a component dies, you spin up another while the
rest of the application continues to function.
Scalability
Smaller components take up fewer resources and
can be scaled to meet increasing demand of that
component only.
Relationship to the business
Microservice architectures are split along business
domain boundaries, increasing independence and
understanding across the organization
SUPERCHARGE MICROSERVICES WITH REDIS
10. Benefits Of Microservices
SUPERCHARGE MICROSERVICES WITH REDIS
1. Number of deployments per day
2. Time To Market the new features
3. Service availability
4. Number of production issues
Continues deployment
integration with slack
11. SUPERCHARGE MICROSERVICES WITH REDIS
Login Public API (Gateway)
Profile Matches Comm Badging NewsfeedPhotos Config
Match Profile DashboardInbox
Message bus
Nodejs App Stack
Eharmony Microservices Architecture
CMP User ActivityUser Pairings Scorer/Modeling
Event ListenerMatching Batch Jobs
User ServiceMatch Maker
Aggregation Services
Core Services
Persistance
Matching
12. SUPERCHARGE MICROSERVICES WITH REDIS
Public API (Gateway)
Profile Matches
Communication
BadgingPhotos
Message bus
Communication flow between services
Dashboard
Newsfeed
Match Profile
Matching services/jobs
13. • Redis is an open source (BSD licensed),
• In-memory data structure key-value store
• Can be used as a database, cache and message broker.
• Primary – Replica architecture
• Provides high availability via Redis Sentinel
• Automatic partitioning with Redis Cluster
• Rich set of operations on various data structures
• Client libraries for almost all popular languages
• Large adoption and great community support
• Single threaded and supports atomic operations
What is redis?
SUPERCHARGE MICROSERVICES WITH REDIS
14. Redis data structures
Strings
Binary-safe strings is most commonly used data
structure to store simple key-value data.
Lists
Collection of string elements sorted in insertion
order (linked lists).
Sets
Collection of unique, unsorted string elements.
Sorted sets
Similar to set with every element associated to
floating number value, called SCORE. Supports
range queries.
SUPERCHARGE MICROSERVICES WITH REDIS
Hashes
Which are maps composed of fields associated with
values. Both the field and value are strings.
HyperLogLogs
Probabilistic data structure used in order to count
unique things.
15. Redis deployment options
SUPERCHARGE MICROSERVICES WITH REDIS
M
S SSnapshot/AOF
• Persistence
• Snapshot for periodic backup
• AOF for every write ( more reliable)
• Replication
• Data will be replicated to read-only slaves
• Failover : Manual
M
S S
• Persistence
• Snapshot for periodic backup
• AOF for every write ( more reliable)
• Replication
• Data will be replicated to read-only slaves
• Failover :
• Automatic failover through sentinel
Sent
inel
Sent
inel
Sent
inel
S1
• Persistence
• Snapshot for periodic backup
• AOF for every write ( more reliable)
• Flash optimized storage with redis labs cluster
• Replication
• Data will be replicated to read-only slaves
• Failover :
• Automatic failover through cluster
M2
M1
S2
Keys A - N
Keys O - Z
17. SUPERCHARGE MICROSERVICES WITH REDIS
Login Public API (Gateway)
Profile Matches Comm Badging NewsfeedPhotos
Nodejs App Stack
Redis as auth store
Refresh tokens Access tokens
18. Redis as auth store
SUPERCHARGE MICROSERVICES WITH REDIS
• Simple string key-value based store
• Token as key and Auth object as value
• Access token has shorter TTL
• Refresh has longer TTL
• JEDIS client library ( SpringData)
• Leveraging RedisLabs replication
19. Redis as auth store
SUPERCHARGE MICROSERVICES WITH REDIS
JedisPoolConfig poolConfig = new JedisPoolConfig();
JedisConnectionFactory cf = new JedisConnectionFactory();
cf.setHostName({hostname}); cf.setPort({port});
cf.setPoolConfig(poolConfig );
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(cf);
redisTemplate.opsForValue(). set(tokenKey, accesstoken, duration, CACHE_TTL_UNITS);
redisAccessTokenTemplate.opsForValue().get(tokenKey);
redisAccessTokenTemplate.delete(accessToken.getTokenId());
-bash-4.1$ ./redis-cli -p XXXX
127.0.0.1:XXXX> get "661295e5-0e4c-XX”
"{"atVal":"661295e5-0e4c-XX",""authorities":[...}”
127.0.0.1:XXXX> ttl "661295e5-0e4c-XX”
(integer) 132888
Client Configuration
Operations
Redis CLI
20. Redis as auth store - Performance
SUPERCHARGE MICROSERVICES WITH REDIS
21. Matching
User
Service
SUPERCHARGE MICROSERVICES WITH REDIS
Message bus
Redis as matching user store
CMP User Activity
User TimelinePairingsMatch maker
Scorer
Modeling
FeatureX
User Store
MAS
Matching Batch Jobs Matching Event Listener
22. SUPERCHARGE MICROSERVICES WITH REDIS
• Hashes data structure
• Data stored in binrary format - Protocol buffers
• UserId as key
• Various user data sections as categories for Map keys
• Ex: User Info, Photos, Activity
• JEDIS client library ( SpringData)
• Leveragin RedisLabs cluster with 6 shards
• Leveraging RedisLabs Flash storage
Redis as matching user store
23. Redis as matching user store
SUPERCHARGE MICROSERVICES WITH REDIS
public Map<String, V> fetchValues(final Iterable<String> keys) {
List results = redisTemplate.executePipelined(new SessionCallback<Object>() {
public Object execute(RedisOperations operations) {
Iterator var2 = keys.iterator();
while(var2.hasNext()) {
operations.opsForHash().entries((String)var2.next());
}
}});
operations.watch(key);
byte[] hashValue = (byte[])hashOperations.get(key, hashKey);
T value = valueSerializer.deserialize(hashKey, hashValue);
value = merger.merge(key, value);
byte[] mergedHashValue = valueSerializer.serialize(hashKey, value);
operations.multi();
hashOperations.put(key, hashKey, mergedHashValue);
List<Object> execResult = operations.exec();
//deserialize to proto...
if(hashKey.equalsIgnoreCase("user-activity"))
return ActivityProto.parseFrom(hashValue);
Fetch Entries in batch
Partial updates
”user:123”:
“activity”: {},
”profile”:{},
“photos”:{},
“questionnaire”:{},
”user:124”:
“activity”: {},
”profile”:{},
“photos”:{},
“questionnaire”:{},
24. SUPERCHARGE MICROSERVICES WITH REDIS
Public API (Gateway)
Profile Matches Comm
Badge API
Photos
Redis as badges store
Badge Store
Badge
Processor
Message bus
25. Redis as badges store
SUPERCHARGE MICROSERVICES WITH REDIS
• Hashes data structure
• Leveraging atomic counters
• UserId as key
• Various badge categories as Map keys
• Ex: Photos, Matches, Activity
• Accumulators as values
• JEDIS client library ( SpringData)
• Leveraging RedisLabs Flash storage
27. Redis as Badges Store
SUPERCHARGE MICROSERVICES WITH REDIS
port 5002
sentinel monitor master-badeges {masternode ip} {port} 1
sentinel down-after-milliseconds master-badges 10000
sentinel failover-timeout master-badges 20000
sentinel config-epoch master-badges 94
# Generated by CONFIG REWRITE
sentinel leader-epoch master-badges 96
sentinel known-slave master-badges {slavenode ip} {port}
sentinel known-sentinel master-badges {sentinel2} 5002 eb42be8
sentinel known-sentinel master-badges {sentinel3} 5002 9243503
sentinel current-epoch 96
Sentinel Configuration
M
S S
• Persistence
• Snapshot for periodic backup
• AOF for every write ( more reliable)
• Replication
• Data will be replicated to read-only slaves
• Failover :
• Automatic failover through sentinel
Sent
inel
Sent
inel
Sent
inel
28. SUPERCHARGE MICROSERVICES WITH REDIS
Public API (Gateway)
Match Save
Service
Redis as speed store in lambda architecture
Delta Store
Message bus
Match Query
Service
Batch Store
Match Events
Processor
Match creation jobs
29. SUPERCHARGE MICROSERVICES WITH REDIS
CDN
Redis sorted sets for Security
Delta Store
Gateway/Router
Profile Matches Comm NewsfeedPhotos
Admin
Login
Refresh tokens Access tokensAccess Tokens Refresh Tokens
Block/unblock
IP/User Agent
Logs
Aggregates
Block Access
Block Access
30. Redis sorted sets for Security
SUPERCHARGE MICROSERVICES WITH REDIS
• Connecting redis from spark jobs
• Leveraging Sorted Sets to find the top N anomalies to block
• Single threaded atomic operations better suited to store accumulators from spark
• Leveraging kafka window operation for streaming
• JEDIS client library ( SpringData)
• Leveraging sentinel for auto failover
32. Redis sorted sets for security
SUPERCHARGE MICROSERVICES WITH REDIS
API BOT mitigation
33. SUPERCHARGE MICROSERVICES WITH REDIS
Redis pub/sub for configurations
Config Service
ServiceServiceServiceService ServiceServiceServiceService ServiceServiceServiceService
Redis Pub/Sub
Gateway
34. Many more use cases…
SUPERCHARGE MICROSERVICES WITH REDIS
• Redis can be used as hibernate second level cache
• Using Redis to rate control the API usage by IP/UA in securely
• Actively migrating user service to Redis using hashes
• Planning to migrate newsfeed, profile and pairings stores