Robust function characteristics
- Avoid long-running functions
- Plan cross-function communication
- Write functions to be stateless
- Write defensive functions
- Security
- Concurrency
Scaling
- Event driven scaling
- Concurrency in Function App Concurrency refers to the ability of a service to handle multiple requests or operations simultaneously. This can be achieved by
- Parallelism Executing multiple tasks at the same time on different cpu/machine
- Overlapping Execution Perform operation in a way that they dont block each other
Concurreny is achived by
-Thread pools
Assigning threads to handle incoming requests
-Async Operation
Async communication patterns to decouple tasks.
-Concurrency control mechanism
Pessimistic locking
Locking entire row to prevent users from modifying data that affects the current userOptimistic Concurrency
Versioning
event driven architecture
Static Concurrency
Dynamic Concurrency
Fuction App Design Pattern
- Database per Service - each service has its own private database
- Shared database - services share a database
- Saga - use sagas, which a sequences of local transactions, to maintain data consistency across services
- Command-side replica - maintain a queryable replica of data in a service that implements a command
- API Composition - implement queries by invoking the services that own the data and performing an in-memory join
- CQRS - implement queries by maintaining one or more materialized views that can be efficiently queried
- Domain event - publish an event whenever data changes
- Event sourcing - persist aggregates as a sequence of events
- Event based pattern In this way it can improve the speed, endurance and resilience of the process.
-
Async Pattern
With Async approachit eliminates blocking callConsider async/await misuses anti patterns
Concurrency settings in host.json
"extensions": {
"http": {
"routePrefix": "api",
"maxOutstandingRequests": 200,
"maxConcurrentRequests": 100,
"dynamicThrottlesEnabled": true,
"hsts": {
"isEnabled": true,
"maxAge": "10"
},
"customHeaders": {
"X-Content-Type-Options": "nosniff"
}
}
}
Idempotent Design best practices
- Verify input
- Verify data freshness
- Verify existence for update and delete operations
- Duplicate detection
- Concurrency control Link
Problem with Distributed Transaction
Problem with ACID
--
Saga Design Pattern
Optimistic Locking
- Read the record and note the version. Use this version for writing the record
Pessimistic Locking
- Apply exclusive lock until finished the operation
Top comments (0)