Azure / Azure/azure-functions-host

Documentation: Clarify in-memory state behavior and persistence recommendations

Open
#11,626 0 comments 0 reactions 1 assignee Claimed by @fabiocav View on GitHub
area: developer-experience documentation enhancement
Dominant language
C#
Stars
2k
Forks
482
Avg merge
2d 12h
Merged PRs (30d)
38

Description

## Summary
When developing Azure Functions with in-memory storage (e.g., using global variables or Maps for caching/state), the data is lost when:
- The function app restarts
- The function scales to new instances
- During local development when `func start` is restarted

This can lead to confusing behavior during development and testing, where data created in one session is not available after restart.

## Reproduction Steps
1. Create a function that stores data in a global variable/Map
2. Call the function to store some data
3. Restart `func start` (locally) or trigger a function app restart (in Azure)
4. Attempt to retrieve the previously stored data
5. Data is not found (404/null)

## Suggestion
Consider adding documentation or warnings that:
1. Clarify that in-memory state is ephemeral and instance-specific
2. Recommend persistent storage options (Azure Table Storage, Cosmos DB, Redis Cache) for any data that needs to survive restarts
3. Perhaps emit a warning in the Functions runtime when global state modifications are detected, suggesting persistent alternatives

## Environment
- Azure Functions Core Tools: 4.6.0
- Runtime: Node.js v4 programming model
- OS: macOS

## Related
This is a documentation/developer experience issue, not a bug. The behavior is expected, but could be better communicated to developers new to serverless.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.