State Management
The Decision
Best will use in-memory shell variables for state management.
The Context
Best will maintain state between function calls to allow for a simple API which follows "normal" bash syntax. This means we need some state management mechanism.
it "should _____"; expect _____; to_be _____
it "should not_____"; expect _____; not; to_be _____
it "should_____"; {
do_something
do_something_else
expect _____
to_be _____
}
Trade-offs
- Speed: declaring and updating shell variables should be faster than file system i/o
- Memory: managing only a few shell variables should limit memory usage
- Security: namespacing shell variables should avoid collisions with environment variables
- Availability: exported shell variables are available in subshells
- Dependencies: exporting shell variables requires no runtime dependencies
Alternatives Considered
- Piping values from one function to the next
- Temporary files
- Named pipes (FIFOs)
- Key/Value store (Redis)
- Database (SQLite)
The Consequences
Using in-memory shell variables for state management should come with these benefits:
- High performance
- Low memory usage
- Reasonable security
- High availability
- No runtime dependencies
Reevaluate the decision if these benefits are not realized or other downsides are discovered.