Architectural patterns from AzureSDK that apply to any HTTP-based cloud SDK.
BEAM Advantages
Official SDKs can't assume: lightweight processes, :telemetry, supervision trees, Broadway/Flow/Explorer, Livebook, hot upgrades.
A BEAM-native SDK leverages these by design.
Layered Architecture
Service Modules (Blob, S3) — Public API
Service Clients — Configuration
Core Pipeline — Cross-cutting concerns
Identity / Credentials — Authentication
Transport (Req → Finch → Mint) — HTTPService modules never import HTTP libraries.
Design Principles
1. Clients are data, not processes — passable structs, not hidden Agents.
2. Credentials are values — construct at app boundary, pass to clients.
3. Pipelines compose middleware — auth, retry, telemetry as modules.
4. Errors are structs — {:error, %Error{status:, code:, ...}}.
5. Internal formats stay internal — parse XML/JSON, return maps.
6. Telemetry at two levels — operations (business) and requests (infra).
OTP Patterns
TokenCache (v0.2.0) — supervised process, single refresh point.
Broadway (v0.6.0) — blob producer with backpressure.
Flow (v0.6.0) — parallel uploads with Flow.map.
Testing
| Layer | Type | Tool |
|---|---|---|
| Signing | Property | StreamData |
| Parsing | Unit | Fixtures |
| Retry | Unit | Mock responses |
| E2E | Integration | Local emulator |
Azurite (Azure), LocalStack (AWS), fake-gcs-server (GCP).
Namespace Reservation
Ship stubs on day one:
defmodule AzureSDK.Storage.Queue do
@moduledoc "Planned v0.3.0."
endDocumentation as Code
plans/— whyguides/— how to thinklivebooks/— how to do (CI-validated)
v0.1.0 Lessons
- Research before code prevented dead ends
- Pipeline first made Blob easy
- Azurite reveals signing edge cases (double account name)
- Disable Req retry to avoid double layers
:telemetry.executeis cheap, invaluable
Cross-Cloud Pattern
| Concept | Azure | AWS (hypothetical) |
|---|---|---|
| Credential | SharedKey | AccessKey |
| Signing | HMAC-SHA256 | SigV4 |
| Pipeline | Core.Pipeline | Same pattern |
| Emulator | Azurite | LocalStack |
| Events | [:azure_sdk, ...] | [:ex_aws, ...] |
Architecture transfers; signing and parsers change per cloud.
Further Reading
plans/architecture.mdguides/building_sdk_pipelines_with_req.mdguides/telemetry_driven_sdk_design.md