Cyclic apps run on read-only file systems amd do not retain or share memory across compute instances.
Limitations and Solutions
Special precautions should be used for the following use-cases:
Basic session implementations are usually built with the assumption that the server process is never interrupted. This can be an issue even in stateful environments, where a server re-start will cause sessions to be lost. With serverless runtimes, re-starts happen quickly (~0.2s) and frequently.
Best practices for stateful environments will dictate that sessions should be backed up to a database. With serverless, storing sessions in a database is a must. There are many libraries and session extensions that enable this for a variety of databases.
Check out our npm package that will let you use apps' built-in AWS DynamoDB database for session storage. >> @cyclic.sh/session-store
Serverless apps run on read-only file systems. This means it is impossible to persistently store files to disk.
Cyclic exposes many features of AWS S3 directly to your apps. To handle uploads directly to the object store, S3 can be used to generate pre-signed GET, PUT and POST urls than can be used by a client to upload and download files over the 6MB api size limitation.
Processing and Uploading
/tmp directory can be written to. But it should only be used for intermediary processing. Either upload the result to an object store or download to the client. An example use case for
/tmp may be to create thumbnail images, store them in /tmp, and then upload them to S3.
A popular pattern with many tutorials is to simulate a database by reading and writing records to and from a
db.json file. In traditional server environments, this pattern may work for some very low volume of read's and write's, it will very quickly become vulnerable to race conditions and should be avoided even in those environments.
While it is possible to write to the
/tmp directory in a stateless runtime, the
/tmp directory is not shared between multiple instances of the application and is lost after each shutdown. This makes the same issues that arise in a stateful environment immediately apparent.
Do not use a
json file as your database. Cyclic has a database you can use for free.