@siglo/kafka 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +17 -18
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -6,7 +6,9 @@
6
6
 
7
7
  ## 1. Overview & Architecture
8
8
 
9
- In an event-driven architecture, Kafka delivers partitioned event streams to consumer groups. The `@siglo/kafka` adapter handles incoming messages, ensures exactly-once semantics via an `IdempotencyStore`, and executes the workflow within configured timeout bounds:
9
+ In an event-driven architecture, Kafka delivers partitioned event streams to consumer groups. The `@siglo/kafka` adapter handles incoming messages with at-least-once processing semantics, coordinates deduplication via an `IdempotencyStore`, and executes the workflow within configured timeout bounds.
10
+
11
+ > **Note on Guarantees**: Claims and cached results do not make external side-effects atomic with record completion. When a Kafka message is delivered, the whole workflow executes from the beginning; it does not automatically resume at the last successful step. A crash after an external effect (e.g. payment charge) succeeds but before claim completion leaves an in-progress claim until expiry, which may repeat the external effect upon message redelivery. Workflows must design external effects to be idempotent or supply provider-level deduplication keys.
10
12
 
11
13
  ```mermaid
12
14
  flowchart TD
@@ -41,24 +43,21 @@ flowchart TD
41
43
  S10 --> Commit["Commit Kafka Offset"]
42
44
  ```
43
45
 
44
- ### Why In-Process Execution is Vastly Superior for 90%+ of Workloads
46
+ ### In-Process Execution Architectural Trade-offs
45
47
 
46
- | Dimension | In-Process Orchestration (`Siglo`) | Distributed Step Orchestration (Temporal / Step Functions) |
48
+ | Dimension | In-Process Orchestration (`Siglo`) | Distributed Step Orchestration |
47
49
  | :--- | :--- | :--- |
48
- | **Step-to-Step Latency** | **Microseconds** ($\approx 1\text{–}5\ \mu\text{s}$) — Direct async promise resolution. | **Milliseconds** ($\approx 15\text{–}100\ \text{ms}$) — Every step requires network RPC, queue write, and DB commit. |
49
- | **End-to-End Latency (10 Steps)** | $\approx \mathbf{5\text{–}20\ \text{ms}}$ (pure business logic time) | $\approx \mathbf{200\text{–}1000\ \text{ms}}$ (dominated by orchestration network latency) |
50
- | **Throughput per Node** | **10,000+ msgs/sec** (bounded only by CPU and I/O) | Typically 500–2,000 ops/sec (queue/database bottlenecks) |
51
- | **Payload Limitations** | **None** — Pass TypeScript domain models, Buffers, Maps, or Streams in memory. | **Strict Limits** — Payloads must serialize to JSON (e.g., SQS 256 KB, Temporal 2 MB limits). |
52
- | **Infrastructure Overhead** | **Zero** — Runs directly inside your application container. | **Heavy** — Requires external clusters (History, Matching, Frontend engines, Cassandra/Postgres). |
53
- | **Debugging & Local Testing** | **Trivial** — Set standard debugger breakpoints stepping from Step 1 to Step 2. | **Difficult** — Requires cross-machine distributed trace correlation and event replay. |
54
- | **Saga Rollback Latency** | **Immediate** — Atomic reverse rollback in local memory if Step 8 fails. | **Delayed** — Rollback messages queue behind other cluster tasks. |
55
-
56
- #### 1. The "10 Network Hops" Tax
57
- In systems that distribute every individual step to different servers:
58
- $$\text{Total Overhead} = 10 \times (\text{JSON Serialization} + \text{Queue Network Write} + \text{Broker Scheduling} + \text{Queue Network Read} + \text{Deserialization})$$
59
- In such systems, **95% of total workflow duration is spent waiting for network hops and queue contention**, and only 5% executing real code. In `Siglo`, Step 1 immediately yields to Step 2 in memory with zero serialization penalty.
60
-
61
- #### 2. How High-Throughput Scaling Actually Works
50
+ | **Step-to-Step Invocation** | Direct in-memory async promise chaining. | Every step requires network RPC, queue write, and external coordination. |
51
+ | **Execution Boundary** | Runs full workflow in-process on consumer node. | Dispatches individual steps across cluster workers. |
52
+ | **Payload Handling** | Pass rich domain models, Buffers, Maps, or Streams directly in memory. | Payloads must be serialized to JSON across each step boundary. |
53
+ | **Infrastructure Overhead** | Runs directly inside your application container with no extra engine servers. | Requires external orchestrator clusters and database infrastructure. |
54
+ | **Debugging & Local Testing** | Standard debugger breakpoints stepping directly between steps. | Requires cross-machine distributed trace correlation and event replay. |
55
+ | **Saga Compensation** | Immediate in-process reverse rollback if downstream step fails. | Rollback messages queue behind other cluster tasks. |
56
+
57
+ #### 1. In-Process vs. Multi-Hop Step Orchestration
58
+ In systems that distribute every individual step to different servers across a network, each step boundary incurs serialization, broker scheduling, and network transfer overhead. In `Siglo`, Step 1 yields to Step 2 directly in memory with zero network latency.
59
+
60
+ #### 2. Horizontally Scaling via Partitions
62
61
  Work is scaled horizontally by **Kafka Partitions (Message-Level Distribution)**, not by splitting individual steps across machines:
63
62
 
64
63
  ```mermaid
@@ -202,7 +201,7 @@ export interface SigloKafkaMessage {
202
201
  | `input` | `(message: SigloKafkaMessage) => Promise<TInput> \| TInput` | JSON parser on `message.value` | Custom transformer converting Kafka record into workflow input. |
203
202
  | `output` | `(result: any, message: SigloKafkaMessage) => Promise<TOutput> \| TOutput` | `result` | Custom post-processor formatting the workflow output. |
204
203
  | `idempotencyStore` | `IdempotencyStore` | `undefined` | Distributed store (e.g., `RedisIdempotencyStore` or `PostgresIdempotencyStore`) to prevent duplicate processing. |
205
- | `idempotencyTtlMs` | `number` | `86400000` (24h) | Time-to-live for idempotency claim lock. |
204
+ | `idempotencyTtlMs` | `number` | `undefined` | Time-to-live for idempotency claim lock. Passed through to store (Redis/Postgres default: 24h; InMemory has no default expiration unless specified). |
206
205
  | `timeout` | `number` | `undefined` | SLA execution timeout in milliseconds. |
207
206
  | `namespace` | `string \| ((message: SigloKafkaMessage) => string \| undefined)` | `message.headers['x-namespace']` | Namespace identifier for tenant partitioning. |
208
207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siglo/kafka",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Kafka consumer message handler and event streaming adapter for Siglo workflows",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",