Go, memcached,
microservices
2016/09/27 cache_night
@mosa_siru
@mosa_siru ( )
•
• 2
@mosa_siru as engineer
• DeNA
• Gunosy
• CTO
1.
2. cache
3. cache
4. microservices
Cache is hard
• Cache Invalidation
• There are only two hard things in Computer Science: cache
invalidation and naming things. -- Phil Karlton
•
• TTL
•
• thundering herd
•
•
• DB
Cache Invalidation
Cache Invalidation
• (DB)


Cache Invalidation
• DB
memcached
• ( API
memcached ) TTL
Cache Invalidation
• Invalidation
•
• 

ID
thundering herd
Thundering Herd
• expire
(DB)
• DB
•


• 2016/06 KDDI 

•
•
•
•
•
•
•
•
•
• Push 

•
•
• 2
get
(1)
1. local memd 2.
(2)
1. local memd
2.
remote
4. local set
3.
(3)
1. local memd
2.
remote
6. local set
4.
3. DB
5. remote set
• TTL (5s-60s) 

TTL (60s-1h) invalidation
updatedelete
• local memd
• DB thundering herd
• local memd TTL invalidation


local memd
•
insert invalidation
insertdelete
• memcached
• redis
• go process cache
• go groupcache
• File DB
Redis
•
•
• 

•
Go process cache
•
•
• local, remote
• remote
Go groupcache
• google memd
local/remote
•
• expire …
File DB
•
File DB(LevelDB )
•
•
•
memcached
•
•
• AWS Elasticache
• JSON msgpack
go memcached client
go memcached client
•
1. bradfitz/gomemcache
2. douban/golibmc
1. gomemcache Pros
• (600star)
• go
1. gomemcache Cons
• 1 issue, PR
• memcached
• SetMulti,
DeleteMulti
1. gomemcache Cons
• TCP 2
(2 )
• 2 configurable PR
•
memcached
•
2. golibmc Pros
• C
• SetMulti
• ”noreply"
(TCP 1 )
• issue PR 2
2. golibmc Cons
• Python libmc (320start)
golibmc
• C
2. golibmc Cons
• goroutine 1Client 1
•
• Client
gomemcache
• golibmc
•
• issue PR 2
• SetMulti
•
•
go
1. local memd
2.
remote
6. local set
4.
3. DB
5. remote set
1
get multi
get multi
select …

where id in
…
set multi
set multi
ID( ) 

get, set 1
• https://github.com/mosasiru/memd
•
• GetOrSet
• GetOrSetMulti
GetOrSet
• local/remote memd
GetOrSetMulti
• local/remote memd
GetMulti/SetMulti
mosasiru/memd
• 

ver0.1 … patch is welcome!!!!
microservices 

microservices
•
• API
• DB
• AWS security group/IAM
•
microservices
• API
• API
microservices
• cache
• invalidation
invalidation
• (DB) write read 

• cache invalidation
write read
invalidation
• cache read/write 1
• cache key 1
• consistent hash 1
write
DELETE /hoge/cache
delete
Worker API
…
CDN
• CDN
• URL invalidation 

https://...?t=1474969378
Cache is hard…
Gunosy
@mosa_siru

Go, memcached, microservices