Get Unlimited Contributor Access to the all ExamTopics Exams!
Take advantage of PDF Files for 1000+ Exams along with community discussions and pass IT Certification Exams Easily.
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?
A.
The session variable is local to just a single instance
B.
The session variable is being overwritten in Cloud Datastore
C.
The URL of the API needs to be modified to prevent caching
D.
The HTTP Expires header needs to be set to -1 stop caching
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 `sessions` is recreated for each container, it might store different data.
The problem here is that this Flask app is stateful. The `sessions` variable 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.
Very well stated, jack. I just wanted to point, GAE is a webserver platform anyway, so making application stateless or stateful is up to the developer and has nothing to do with GAE. The issue is about session consistency. GAE spin new container if there's a need, and based on the code, the session is stored locally, this means, there's no consistency between container, and there's no grantee that the same container might serve the same user. Thank you Jack, very good explanation
The most likely cause of the reported issue is that the session variable is local to just a single instance.
In the code provided, the sessions variable is a dictionary that stores the viewed news articles for each user. However, this variable is only stored in memory on the instance that handles the request, and it is not shared between instances. Therefore, when a new request is handled by a different instance, it will not have access to the same session data, and the user may see previously viewed news articles.
To solve this problem, a shared session management system should be used that can be accessed by all instances. Google App Engine provides a few options for session management, such as using Memcache or Cloud Datastore to store the session data. By using a shared session management system, all instances can access the same session data, and users will not see previously viewed news articles.
A
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.
To fix this issue, you could consider using a persistent storage solution, such as Cloud Datastore or Cloud SQL, to store the session data in a way that is shared across all instances of the application. This would allow you to maintain a consistent view of the session data for each user across all instances of the application.
Other potential causes for this issue, such as modifying the URL of the API to prevent caching or setting the HTTP Expires header to -1 to stop caching, are not related to the issue described in the code and would not likely address the problem.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
jackdbd
Highly Voted 1 year, 11 months agoH_S
1 year, 10 months agoAzureDP900
1 year, 6 months agoomermahgoub
1 year, 4 months agoJoeShmoe
Highly Voted 4 years, 5 months agoAmor_Apprendido
Most Recent 6 months, 3 weeks agoheretolearnazure
8 months agoBadri9898
1 year agosimonab23
1 year, 2 months agojay9114
1 year, 3 months agoomermahgoub
1 year, 4 months agoomermahgoub
1 year, 4 months agoAmrit123_
1 year, 4 months agoangelumesh
1 year, 4 months agoRacinely
1 year, 5 months agoMahmoud_E
1 year, 6 months agominmin2020
1 year, 6 months agosgofficial
1 year, 8 months agojay9114
1 year, 9 months agobackhand
1 year, 9 months agonicoueron
1 year, 10 months ago