Topic 1 Question 4
A news feed web service has the following code running on Google App Engine. During peak load, users report that they can see news articles they already viewed. What is the most likely cause of this problem?

The session variable is local to just a single instance
The session variable is being overwritten in Cloud Datastore
The URL of the API needs to be modified to prevent caching
The HTTP Expires header needs to be set to -1 stop caching
ユーザの投票
コメント(17)
It's A. AppEngine spins up new containers automatically according to the load. During peak traffic, HTTP requests originated by the same user could be served by different containers. Given that the variable
sessionsis recreated for each container, it might store different data. The problem here is that this Flask app is stateful. Thesessionsvariable is the state of this app. And stateful variables in AppEngine / Cloud Run / Cloud Functions are problematic. A solution would be to store the session in some database (e.g. Firestore, Memorystore) and retrieve it from there. This way the app would fetch the session from a single place and would be stateless.👍 72jackdbd2022/05/12A is correct
👍 29JoeShmoe2019/11/14A The most likely cause of the issue described in the code is that the session variable is local to just a single instance. In this code, the session variable is defined as a local dictionary within the Flask application. This means that it is not shared across different instances of the application and will not be persisted between requests. As a result, when the application is running on multiple instances, each instance will have its own local copy of the session variable, and users may see news articles that they have already viewed on other instances.
👍 4omermahgoub2022/12/20
シャッフルモード