askrobots / dbbasic Public

Model-config web apps: describe the app in configuration instead of writing code. Built on Polars and DuckDB.

0 downloads

dbbasic/docs/paradigms/ACTOR_SYSTEMS_IN_CONFIG.yaml
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add DBBasic crate engine logo and update README 0d628db 1 year, 2 months ago History
ACTOR_SYSTEMS_IN_CONFIG.yaml · 6.3 KB · 275 lines
1# Actor Systems in Config
2# Erlang/Elixir/Akka patterns that MVC couldn't handle
3# Concurrent, distributed, fault-tolerant systems
4
5name: "Actor-Based Application"
6paradigm: "Actor Model (Erlang/Elixir/Akka)"
7why_mvc_failed: "Shared mutable state doesn't scale"
8
9# ==========================================
10# ACTOR DEFINITIONS → CONFIG
11# ==========================================
12actors:
13 # Each actor is isolated, has state, processes messages
14
15 UserActor:
16 state:
17 user_id: "string"
18 balance: "float"
19 transactions: "list"
20
21 messages:
22 Deposit:
23 params: [amount]
24 handler: |
25 state.balance += amount
26 state.transactions.append({type: 'deposit', amount})
27 reply(:ok, state.balance)
28
29 Withdraw:
30 params: [amount]
31 handler: |
32 if state.balance >= amount:
33 state.balance -= amount
34 reply(:ok, state.balance)
35 else:
36 reply(:error, 'insufficient_funds')
37
38 GetBalance:
39 handler: "reply(state.balance)"
40
41 supervision:
42 strategy: "one_for_one" # Restart only failed actor
43 max_restarts: 3
44 max_seconds: 60
45
46 OrderProcessor:
47 state:
48 pending_orders: "queue"
49 processed_count: "integer"
50
51 messages:
52 ProcessOrder:
53 params: [order]
54 handler: |
55 validate_order(order)
56 charge_payment(order)
57 send_to_fulfillment(order)
58 state.processed_count += 1
59 broadcast(:order_completed, order)
60
61 mailbox:
62 capacity: 10000
63 overflow: "drop_oldest"
64
65# ==========================================
66# SUPERVISOR TREES → CONFIG
67# ==========================================
68supervision:
69 # Erlang OTP-style supervision
70
71 ApplicationSupervisor:
72 children:
73 - UserSupervisor
74 - OrderSupervisor
75 - CacheSupervisor
76
77 restart_strategy: "one_for_all" # All children restart together
78
79 UserSupervisor:
80 children:
81 - UserRegistry
82 - UserActorPool
83
84 restart_strategy: "rest_for_one" # Restart failed + all after it
85
86 DynamicSupervisor:
87 # Spawns actors on demand
88 child_spec: "UserActor"
89 max_children: 10000
90
91# ==========================================
92# MESSAGE PASSING → CONFIG
93# ==========================================
94messaging:
95 # No shared state, only messages
96
97 patterns:
98 request_reply:
99 timeout: 5000
100 on_timeout: "return :error"
101
102 fire_forget:
103 guaranteed: false
104
105 broadcast:
106 to: "all_actors_in_group"
107
108 routing:
109 # Route messages to actors
110 "/api/users/:id/balance":
111 actor: "UserActor-{id}"
112 message: "GetBalance"
113
114 "/api/orders/process":
115 actor: "OrderProcessor"
116 message: "ProcessOrder"
117 via: "round_robin" # Load balance
118
119# ==========================================
120# DISTRIBUTED ACTORS → CONFIG
121# ==========================================
122clustering:
123 # Actors across multiple nodes
124
125 nodes:
126 - "node1@server1"
127 - "node2@server2"
128 - "node3@server3"
129
130 actor_placement:
131 strategy: "consistent_hashing"
132 replication: 3
133
134 network_splits:
135 strategy: "split_brain_resolver"
136 quorum: 2
137
138# ==========================================
139# PHOENIX LIVEVIEW STYLE → CONFIG
140# ==========================================
141liveview:
142 # Stateful server-rendered components
143
144 Counter:
145 state:
146 count: 0
147
148 mount:
149 handler: "assign(count: 0)"
150
151 events:
152 increment:
153 handler: "state.count += 1; push_update()"
154
155 decrement:
156 handler: "state.count -= 1; push_update()"
157
158 render: |
159 <div>
160 <button phx-click="decrement">-</button>
161 <span>{{ count }}</span>
162 <button phx-click="increment">+</button>
163 </div>
164
165# ==========================================
166# GENSERVER PATTERNS → CONFIG
167# ==========================================
168genservers:
169 # Elixir GenServer behavior
170
171 RateLimiter:
172 init:
173 state: "Map.new()"
174
175 handle_call:
176 check_rate:
177 params: [user_id]
178 handler: |
179 count = Map.get(state, user_id, 0)
180 if count < 100:
181 {:reply, :ok, Map.put(state, user_id, count + 1)}
182 else:
183 {:reply, :rate_limited, state}
184
185 handle_info:
186 reset_counters:
187 handler: "{:noreply, Map.new()}"
188 schedule: "every 1 minute"
189
190# ==========================================
191# EVENT SOURCING → CONFIG
192# ==========================================
193event_sourcing:
194 # Store events, not state
195
196 aggregates:
197 BankAccount:
198 events:
199 - AccountOpened
200 - MoneyDeposited
201 - MoneyWithdrawn
202
203 commands:
204 OpenAccount:
205 validates: "account doesn't exist"
206 emits: "AccountOpened"
207
208 Deposit:
209 validates: "account exists"
210 emits: "MoneyDeposited"
211
212 projections:
213 current_balance:
214 from_events: |
215 events.reduce(0, (bal, event) => {
216 switch(event.type) {
217 case 'MoneyDeposited': return bal + event.amount
218 case 'MoneyWithdrawn': return bal - event.amount
219 }
220 })
221
222# ==========================================
223# SAGA ORCHESTRATION → CONFIG
224# ==========================================
225sagas:
226 # Long-running distributed transactions
227
228 OrderFulfillmentSaga:
229 steps:
230 - ReserveInventory:
231 compensate: "ReleaseInventory"
232
233 - ChargePayment:
234 compensate: "RefundPayment"
235
236 - ShipOrder:
237 compensate: "CancelShipment"
238
239 on_failure:
240 strategy: "compensate_all"
241 notify: "admin"
242
243# ==========================================
244# BACKPRESSURE & FLOW CONTROL → CONFIG
245# ==========================================
246flow_control:
247 # Handle overload gracefully
248
249 backpressure:
250 strategy: "drop_newest"
251 threshold: 1000
252
253 circuit_breakers:
254 external_api:
255 failure_threshold: 5
256 timeout: 30000
257 reset_after: 60000
258
259# ==========================================
260# WHY THIS MATTERS
261# ==========================================
262# MVC frameworks (Rails/Django) assume:
263# - Shared mutable state (database)
264# - Request/response cycle
265# - Synchronous processing
266# - Single server (originally)
267#
268# Actor systems assume:
269# - Isolated actors with private state
270# - Message passing
271# - Asynchronous by default
272# - Distributed from day one
273#
274# DBBasic handles BOTH paradigms in config
275# ==========================================