Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Professional Cloud Architect All Questions

View all questions & answers for the Professional Cloud Architect exam

Exam Professional Cloud Architect topic 1 question 4 discussion

Actual exam question from Google's Professional Cloud Architect
Question #: 4
Topic #: 1
[All Professional Cloud Architect Questions]

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
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
jackdbd
Highly Voted 2 months ago
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.
upvoted 114 times
omermahgoub
1 year, 11 months ago
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
upvoted 14 times
...
...
JoeShmoe
Highly Voted 5 years ago
A is correct
upvoted 29 times
...
Ekramy_Elnaggar
Most Recent 1 week, 5 days ago
Selected Answer: A
Answer is A. The session variable is local to just a single instance. Here's why: * App Engine Instances: Google App Engine automatically scales your application by creating multiple instances to handle incoming traffic. Each instance runs independently and has its own memory space. * Session Variable: In the provided code, the `sessions` variable is a simple Python dictionary stored in the memory of each instance. This means each instance has its own copy of the `sessions` data. * The Problem: When a user logs in, their viewed articles are stored in the `sessions` variable of the instance that handled their request. If subsequent requests from the same user are routed to a different instance, that instance won't have any record of the previously viewed articles, causing them to be displayed again.
upvoted 1 times
...
omermahgoub
2 months ago
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.
upvoted 4 times
omermahgoub
1 year, 11 months ago
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.
upvoted 2 times
...
...
Badri9898
2 months ago
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.
upvoted 8 times
...
kurili
2 months, 1 week ago
A.The sessions dictionary is used to store user-specific data, such as which news articles have been viewed. This dictionary is created as an in-memory variable within the Flask app. In a cloud environment, like Google App Engine, the application may be running on multiple instances, especially during peak loads. Since the sessions dictionary is stored in memory, it is local to each instance. This means that if a user is routed to a different instance (due to load balancing), their session data will not be available on that new instance, causing the application to serve news articles they’ve already seen.
upvoted 1 times
...
simonab23
1 year, 10 months ago
A is the right answer
upvoted 1 times
...
jay9114
1 year, 10 months ago
Where in the code does it show that the session variable is local to just a single instance?
upvoted 3 times
...
Amrit123_
1 year, 11 months ago
A is correct
upvoted 1 times
...
angelumesh
1 year, 12 months ago
Selected Answer: A
stateful variable should be in firestore (redis).
upvoted 1 times
...
Racinely
2 years ago
I agree with ackdbd
upvoted 1 times
...
Mahmoud_E
2 years, 1 month ago
Selected Answer: A
A is the correct answer app becoming stateful and it should not be sin case of app engine, cloud run and functions
upvoted 1 times
...
minmin2020
2 years, 1 month ago
Selected Answer: A
A. The session variable is local to just a single instance The others are not relevant
upvoted 1 times
...
sgofficial
2 years, 3 months ago
Thank you that was nice explanation
upvoted 2 times
...
jay9114
2 years, 4 months ago
Where was this presented in the GCP Architecture training & labs?
upvoted 2 times
...
backhand
2 years, 4 months ago
vote A - rule out C,D not thing to do with problem - rule out B, Q is not mention datastore
upvoted 2 times
...
nicoueron
2 years, 4 months ago
Selected Answer: A
A of course, it's just a code pb here
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...