Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is GAE Stateless? What are the implications?

I was once told that GAE is stateless. I understand the concept of statelessness in general but I could use some guidance in conceptually applying it to a GAE-type-system.

I'm asking this question specifically because I an app I've developed appears to be having an interference problem. That is, when two or more people use it at the same time, it becomes confused. (I am continuing to bugtest to confirm that the error only occurs during simultaneous use.) I perceive that there are two ways such interference could theoretically occur: A, incorrect GQL queries getting the wrong db records(I checked this, nope); or b. at the server level. My question: is the latter actually possible? When the app is serving, can one user interfere with another by, say, changing the state of a variable within the program? Or, perhaps, is this prevented by statelessness? I am confused and may have misstated the question. Namaste.

like image 739
cognitiveUpgrade Avatar asked Dec 07 '22 15:12

cognitiveUpgrade


1 Answers

I think you're confusing a few terms. First off, what language are you using? Is this java or python?

The person who told you that GAE is 'stateless' doesn't know what they are talking about, or else you are confused as to what they told you. GAE is a web server platform and the statefulness of your app is up to you. HTTP is a stateless protocol (and GAE is for building web applications which use http) but you can absolutely turn on sessions and achieve statefulness for users that way.

The error condition you are describing is one of concurrency. You have shared resources in GAE (the datastore, memcache, etc) and you also have eventual consistency in the datastore if you are using the High-replication datastore.

GAE does not guarantee that the same server instance will serve multiple requests by the same person, and by default there is no multi-threading (in java anyway, I'm not sure about python). With no multi-threading there will only be 1 person on any instance at any given time. However, if you enable multi-threading you must make sure that your code is thread-safe, or else you can have 2 users modifying a variable on a single instance, but this is not unique to GAE.

You can definitely have 2 users modifying the same datastore entity on 2 different servers or the same memcache entry and you need to code for that case by using transactions, etc. Also with eventual consistency there can be a lag between a write and a read so if you write data and another user immediately reads it they might not get the same value back.

like image 60
Rick Mangi Avatar answered Feb 07 '23 16:02

Rick Mangi