Team in Mercari JP / Category Growth, Catalogs • Joined Mercari JP in November 2018. • Go : Experienced about 1 year in coding as the Production Code. • Community : Kubernetes Meetup, Cloud Native Meetup, etc • My current interests: Go, GCP, Kubernetes, Microservices,etc.
call suppression mechanism.” • If your app receive multiple requests for the same resource, sync/singleflight is helpful. ◦ RDB( master data ) ◦ Image file ◦ Lookup IP address ◦ Client Certs • “x/sync/singleflight” is imported by 81 packages (As of Oct 7 2019). ◦ github.com/hashicorp/consul/agent/consul ◦ gopkg.in/ebay/fabio.v1/cert ▪ https://github.com/fabiolb/fabio/blob/master/cert/source.go https://godoc.org/golang.org/x/sync/singleflight?importers
“net/lookup.go”) The spec is a little bit different between internal/singleflight and x/sync/singleflight. • GoDoc - x/sync/singleflight, GoDoc - internal/singleflight Go Sync ( This repository provides Go concurrency primitives in addition to the ones provided by the language and "sync" and "sync/atomic" packages. ) FYI: a trend of singleflight https://github.com/golang/sync
is going to delete and recommend x/sync/singleflight to use from 1.14. https://go-review.googlesource.com/c/go/+/174080/ https://github.com/golang/go/issues/31697
for lookups for the same host. ◦ LookupIPAddr looks up host using the local resolver. Introduction to Use Case 1 https://github.com/golang/go/blob/release-branch.go1.13/src/net/lookup.go#L204
the technical spec in Microservices ◦ Client ▪ Request the API of GetCatalogComponent to Microservice A ▪ To get the recommended Catalog( ID:1 ) ▪ To get Catalog inserted within 1 week. ◦ Microservice A - BFF layer ▪ GetCatalogComponent provides the recommended Catalog(ID:1) and the Catalog inserted within 1 week as a aggregator. • Request to API of GetCatalog to Microservice B • Request to API of ListCatalogs to Microservice B ◦ Microservice B - Database layer ▪ GetCatalog provides Catalog specified by using ID ▪ ListCatalogs provides Catalog specified by using 1 weeks.
Service HTTP/gRPC Use Case 2 - Overview (after) GetCatalog - id:1 ListCatalog GetCatalog - id:1 ListCatalog - between 7 days catalog singleflight client
• If you need to tune the API that requests the same resource, singleflight will be helpful. • It seems to me that such as BFF in Microservices is easy to apply the use case by using singleflight. • If you have the interests, please check the other use case of other products imported singleflight, https://godoc.org/golang.org/x/sync/singleflight?importers Conclusion