Skip to content

Commit 68fce15

Browse files
committed
removes ractor references
1 parent ce03fb0 commit 68fce15

1 file changed

Lines changed: 85 additions & 0 deletions

File tree

doc/service-api-vs-rest.adoc

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
= Leopard Service-API Whitepaper
2+
:revdate: 2025-08-03
3+
:doctype: whitepaper
4+
5+
== Abstract
6+
Leopard’s NATS Service-API brings full-featured service-to-service communication—complete with discovery, health checks, per-endpoint scaling, and observability—while preserving the simplicity and resilience of asynchronous messaging. This paper contrasts Leopard’s model with traditional REST, outlines its key benefits and trade-offs, and illustrates how Leopard can streamline microservice architectures.
7+
8+
== 1. Introduction
9+
Microservices communicate most often via HTTP/REST today, but REST comes with overhead: service registries, load-balancers, schema/version endpoints, and brittle synchronous request patterns. Leopard leverages NATS’s Service-API layer to deliver:
10+
* **Automatic discovery** via `$SRV.PING/INFO/​STATS` subjects
11+
* **Dynamic load-balanced routing** with queue groups
12+
* **Built-in telemetry** (per-endpoint request counts, latencies, errors)
13+
* **Scalable workers** (Concurrent::FixedThreadPool currently)
14+
* **Asynchronous decoupling** for resilient flows
15+
16+
== 2. Architecture Overview
17+
Leopard embeds a “mini web-framework” in Ruby, registering each endpoint on a NATS subject and grouping instances for load-sharing:
18+
19+
[mermaid,flowchart]
20+
----
21+
flowchart LR
22+
subgraph ServiceInstance
23+
A[NatsApiServer.start] --> B(Registers endpoints)
24+
end
25+
subgraph NATS_Cluster
26+
B --> C[$SRV.INFO.calc]
27+
B --> D[calc.add queue group]
28+
end
29+
E[Client] -->|request("calc.add")| D
30+
D --> F[Worker Thread pool]
31+
F --> G[Handler & Dry::Monads]
32+
G -->|respond()/respond_with_error()| E
33+
----
34+
35+
== 3. Key Benefits
36+
37+
=== 3.1 Automatic Discovery & Monitoring
38+
Leopard services auto-advertise on well-known NATS subjects. Clients can query:
39+
* `$SRV.PING.<name>` – discover live instances & measure RTT
40+
* `$SRV.INFO.<name>` – retrieve endpoint schemas & metadata
41+
* `$SRV.STATS.<name>` – fetch per-endpoint metrics
42+
43+
No external service-registry (Consul, etcd) or custom HTTP health paths required.
44+
45+
=== 3.2 Scaling-Per-Endpoint-Group
46+
Each endpoint—registered with an optional queue group—enjoys native NATS queue-group load balancing. You can:
47+
* Scale thread-pooled workers independently per service
48+
* Horizontally add new service instances without redeploying clients
49+
* Isolate hot-paths (e.g. “reports.generate”) onto dedicated worker farms
50+
51+
=== 3.3 Observability & Telemetry
52+
Leopard exposes stats out-of-the-box:
53+
* Request counts, error counts, processing time
54+
* Custom `on_stats` hooks for business metrics
55+
* Integration with Prometheus or any NATS-capable dashboard
56+
57+
=== 3.4 Asynchronous, Resilient Communication
58+
Unlike blocking HTTP calls, Leopard’s NATS requests can:
59+
* Employ timeouts, retries, and dead-letter queues
60+
* Fit into event-driven pipelines, decoupling producers and consumers
61+
* Maintain throughput under partial outages
62+
63+
== 4. Comparison with REST
64+
[cols="1,1", options="header"]
65+
|===
66+
| Feature | REST (HTTP) | Leopard (NATS Service-API)
67+
68+
| Discovery | External registry | Built-in `$SRV.*` subjects
69+
| Load-balancing| HTTP LB or DNS | Native queue groups
70+
| Telemetry | Custom endpoints | Auto-collected stats
71+
| Latency | Higher overhead | Low-latency messaging
72+
| Coupling | Synchronous | Async, decoupled
73+
| Schema | Swagger/OpenAPI | Optional metadata on endpoints
74+
|===
75+
76+
== 5. Trade-Offs & Considerations
77+
. **Dependency on NATS**
78+
Leopard requires a healthy NATS cluster; network partition or broker outage impacts all services.
79+
. **Learning Curve**
80+
Teams must understand NATS subjects, queue groups, and Service-API conventions.
81+
. **Language Support**
82+
While Leopard is Ruby-centric, NATS Service-API is cross-language—other teams must adopt compatible clients.
83+
84+
== 6. Conclusion
85+
Leopard’s NATS Service-API framework offers a powerful alternative to REST: zero-config discovery, per-endpoint scaling, rich observability, and asynchronous resilience. For high-throughput, low-latency microservice ecosystems, Leopard can simplify infrastructure, reduce boilerplate, and improve operational visibility—while retaining the expressiveness and composability of idiomatic Ruby.

0 commit comments

Comments
 (0)