Skip to content

Commit 28a904b

Browse files
committed
docs: add monolithic function section
1 parent fb85a56 commit 28a904b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,41 @@ This sample project contains an Users function with two distinct set of routes,
11251125
PYTHONPATH="users:${PYTHONPATH}"
11261126
```
11271127

1128-
#### Trade-offs
1128+
### Considerations
1129+
1130+
This utility is optimized for fast startup, minimal feature set, and to quickly on-board customers familiar with frameworks like Flask — it's not meant to be a fully fledged framework.
1131+
1132+
Event Handler naturally leads to a single Lambda function handling multiple routes for a given service, which can be eventually broken into multiple functions.
1133+
1134+
Both single (monolithic) and multiple functions (micro) offer different set of trade-offs worth knowing.
1135+
1136+
!!! tip "Start with a monolithic function and eventually break into multiple functions, if necessary."
1137+
1138+
#### Monolithic function
1139+
1140+
![Monolithic function sample](./../../media/monolithic-function.png)
1141+
1142+
A monolithic function means that your final code artifact will be deployed to a single function. This is generally the best approach to start.
1143+
1144+
**Benefits**
1145+
1146+
* **Code reuse**. It's easier to reason about your project, modularize it and reuse code as it grows. Eventually, it can be turned into a standalone library.
1147+
* **No custom tooling**. Monolithic functions are treated just like normal Python packages; no upfront investment in tooling.
1148+
* **Faster deployment and debugging**. Whether you use all-at-once, linear, or canary deployments, a monolithic function is a single deployable unit. IDEs like PyCharm and VSCode have tooling to quickly profile, visualize, and step through debug any Python package.
1149+
1150+
**Downsides**
1151+
1152+
* **Cold starts**. Frequent deployments and/or high load can diminish the benefit of monolithic functions depending on your latency requirements, due to [Lambda scaling model](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html). Always load test to pragmatically balance between your customer experience and development cognitive load.
1153+
* **Granular security permissions**. The micro function approach enables you to use fine-grained permissions, separate external dependencies & code signing at the function level. Regardless, least privilege can be applied to either approaches.
1154+
* **Higher risk per deployment**. A bad deployment can cause the entire service to stop working while a micro function will limit its blast radius. You can minimize risks by ensuring modules are tested in isolation, use multiple environments in your CI/CD pipeline, and optionally use linear/canary deployments to trade lead time for safety.
1155+
1156+
#### Micro function
1157+
1158+
![Micro function sample](./../../media/micro-function.png)
1159+
1160+
1161+
!!! TODO "rewrite this section"
1162+
11291163

11301164
!!! tip "TL;DR. Balance your latency requirements, cognitive overload, least privilege, and operational overhead to decide between one, few, or many single purpose functions."
11311165

@@ -1139,7 +1173,6 @@ This can also quickly lead to discussions whether it facilitates a monolithic vs
11391173

11401174
**Package size**. Consider Lambda Layers for third-party dependencies and service-level shared code. Treat third-party dependencies as dev dependencies, and Lambda Layers as a mechanism to speed up build and deployments.
11411175

1142-
**Cold start**. High load can diminish the benefit of monolithic functions depending on your latency requirements. Always load test to pragmatically balance between your customer experience and development cognitive load.
11431176

11441177
## Testing your code
11451178

docs/media/micro-function.png

84.8 KB
Loading

docs/media/monolithic-function.png

79.8 KB
Loading

0 commit comments

Comments
 (0)