Somewhat Stateful Serverless Functions on Oracle Cloud Infrastructure — Implementing a DIY Cache

Lucas Jellema
Oracle Developers
Published in
6 min readJan 12, 2020

--

We call them serverless and we consider them stateless. Functions on Oracle Cloud Infrastructure (and on other cloud platforms). Of course, they are neither. They run on servers. And they can carry some state, though largely opportunistic and not reliably.

Functions on OCI run inside a container. The container is started when the function is first invoked. And the container is left running for some time (several minutes) in order to perhaps service additional function requests. While the container keeps running, the state can be retained as well. When the function is, for example, a Node function, global variables can be set and read across requests. For as long as the container keeps running. For which there is no guarantee.

When the number of requests increases to a point where the OCI Functions framework deems it necessary to start a second instance of the container for helping with handling the requests, this second container obviously does not have the state of the first container. At that point, we should consider the state lost.

So if the load on a function is not excessive and it consists of at least one request every 3–6 minutes (I have not yet figured out the exact idle time limit used by OCI Functions for killing the container), the state can be kept. The state could be persisted periodically, to a backend database or some other persistence service or simply to a file on OCI Object…

--

--

Lucas Jellema
Oracle Developers

Lucas Jellema is CTO and IT architect at Conclusion, The Netherlands. He is Oracle ACE Director, one time JavaOne Rockstar and programmer