microservices-demo icon indicating copy to clipboard operation
microservices-demo copied to clipboard

Missing Database in Multi-cluster with Istio

Open saswatmohanty01 opened this issue 4 years ago • 5 comments
trafficstars

Original title of this issue: Cart services in multi cluster istio mode does not keep cart details while refresh browser

Cart services deployed in two Kubernetes cluster with isio has issues as there is no database , session switch between clusters and cart is empty and next refresh cart shows the correct number. Might need something with common database . Is there any fix for it.

saswatmohanty01 avatar Nov 05 '21 17:11 saswatmohanty01

What about leveraging an external service for the redis database? Like for example the Memorystore (redis) service? https://github.com/GoogleCloudPlatform/microservices-demo/blob/master/docs/memorystore.md

mathieu-benoit avatar Nov 05 '21 17:11 mathieu-benoit

Thanks for your response but I am testing this on-prem which is outside GCP.

saswatmohanty01 avatar Nov 05 '21 17:11 saswatmohanty01

Hello, if you're using Istio on-prem, could you set up multicluster service discovery and just have one instance of Redis in one cluster? And route the other cluster's cartservice to it? https://istio.io/latest/docs/setup/install/multicluster/multi-primary/#enable-endpoint-discovery

Or are you already doing this and it's causing that refresh bug?

askmeegs avatar Nov 09 '21 13:11 askmeegs

I just tested this scenario where the in-cluster redis db is in cluster 1 only and not in cluster 2. And I got the issue described here, JFYI.

mathieu-benoit avatar Apr 24 '22 15:04 mathieu-benoit

Actually even with the cleaner and new implementation coming soon (#838) of the cartservice interacting with the redis database, the issue is still here, I just re-tested with the old and new version of cartservice.

And actually, that's not an issue, that's a feature :)

This behavior is due to the implementaton of the SessionId/UserId in the frontend app as a Cookie (shop_session-id) per instance, see here: https://github.com/GoogleCloudPlatform/microservices-demo/blob/65b552273a26714f730253a89321ac8f381882fc/src/frontend/middleware.go#L84

Maybe a way to allow a common redis database across clusters and actually a common SessionId/UserId could be to have an environment variable for either the frontend app or the cartservie app. This environment variable could be for example named UNIQUE_USER_ID_ACCROSS_SESSIONS or something like this, and then either the frontend or the cartservice could use a unique and common value (for example UUI.Empty or equivalent) in order to share the same SessionId/UserId and same cart in the redis database. Sharing my thoughts and findings for potential future implementation around this.

So maybe we want to rename this issue by Have an option to share a unique/common SessionId/UserId accross clusters for the cart?

mathieu-benoit avatar May 28 '22 01:05 mathieu-benoit

These 2 PRS https://github.com/GoogleCloudPlatform/microservices-demo/pull/838 and https://github.com/GoogleCloudPlatform/microservices-demo/pull/1023 now allow to support this scenario.

mathieu-benoit avatar Sep 03 '22 00:09 mathieu-benoit