Commit 29ac1ba
feat(infra): make rate-limit + JWKS caching Redis-switchable
Cloud runs multiple replicas; per-pod IMemoryCache counters multiply
FR-045 OTP limits by replica count, and the old read-modify-write
window let concurrent requests slip past the limit even on one host.
- IRateLimitStore behind OtpRateLimitPolicies: InMemoryRateLimitStore
(Standalone, Interlocked) or RedisRateLimitStore (Cloud) selected by
Redis:ConnectionString — same switch pattern as Database:Provider
- Redis impl is one atomic Lua INCR+PEXPIRE round-trip; fails open
with Error log when Redis is down so a cache outage cannot block
all OTP logins (account lockout still guards verification)
- Apple JWKS moves to HybridCache (L1 always, Redis L2 in Cloud);
raw JSON cached 6h, bad payloads never cached
- StatusHealthJob + Supervisor RateLimitMiddleware stay per-node by
design; C4 diagrams under docs/architecture/c4/caching-rate-limit/
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GjzSCHdeKbADHEuunWkdNq1 parent fed1eaa commit 29ac1ba
64 files changed
Lines changed: 3424 additions & 779 deletions
File tree
- docs/architecture/c4/caching-rate-limit
- src
- Balsm.API
- Balsm.Infrastructure.Migrations.Npgsql
- Balsm.Infrastructure
- Auth
- RateLimit
- Balsm.Supervisor
- Modules
- Account
- Balsm.Account.Api
- Balsm.Account.Application
- Balsm.Account.Infrastructure.Migrations.Sqlite
- Balsm.Account.Infrastructure
- Auth
- Balsm.Auth.Api
- Balsm.Auth.Application
- Balsm.Auth.Infrastructure.Migrations.Sqlite
- Balsm.Auth.Infrastructure
- Handlers
- Customer/Balsm.Customer.Infrastructure
- Deletion
- Balsm.Deletion.Api
- Balsm.Deletion.Application
- Balsm.Deletion.Infrastructure.Migrations.Sqlite
- Balsm.Deletion.Infrastructure
- Disclosure
- Balsm.Disclosure.Api
- Balsm.Disclosure.Application
- Balsm.Disclosure.Infrastructure.Migrations.Sqlite
- Balsm.Disclosure.Infrastructure
- EmergencyQr
- Balsm.EmergencyQr.Api
- Balsm.EmergencyQr.Application
- Balsm.EmergencyQr.Infrastructure.Migrations.Sqlite
- Balsm.EmergencyQr.Infrastructure
- Entity
- Balsm.Entity.Api
- Balsm.Entity.Infrastructure.Migrations.Npgsql
- Balsm.Entity.Infrastructure
- Geofence
- Balsm.Geofence.Infrastructure.Migrations.Sqlite
- Balsm.Geofence.Infrastructure
- Identity
- Balsm.Identity.Api
- Balsm.Identity.Infrastructure.Migrations.Npgsql
- Balsm.Identity.Infrastructure
- Inventory/Balsm.Inventory.Infrastructure
- POS/Balsm.POS.Infrastructure
- Prescription/Balsm.Prescription.Infrastructure
- Sessions
- Balsm.Sessions.Api
- Balsm.Sessions.Application
- Balsm.Sessions.Infrastructure.Migrations.Sqlite
- Balsm.Sessions.Infrastructure
- tests
- Balsm.API.IntegrationTests
- Balsm.API.Tests
- Balsm.Supervisor.Tests
- Modules
- Balsm.Auth.Tests
- Balsm.Deletion.Tests
- Balsm.EmergencyQr.Tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
46 | 51 | | |
47 | 52 | | |
48 | 53 | | |
| |||
56 | 61 | | |
57 | 62 | | |
58 | 63 | | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
375 | 380 | | |
376 | 381 | | |
377 | 382 | | |
| |||
517 | 522 | | |
518 | 523 | | |
519 | 524 | | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
520 | 530 | | |
521 | 531 | | |
522 | 532 | | |
| |||
891 | 901 | | |
892 | 902 | | |
893 | 903 | | |
| 904 | + | |
| 905 | + | |
894 | 906 | | |
895 | 907 | | |
896 | 908 | | |
897 | 909 | | |
898 | 910 | | |
| 911 | + | |
899 | 912 | | |
900 | 913 | | |
901 | 914 | | |
| |||
1145 | 1158 | | |
1146 | 1159 | | |
1147 | 1160 | | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
1148 | 1176 | | |
1149 | 1177 | | |
1150 | 1178 | | |
| |||
1171 | 1199 | | |
1172 | 1200 | | |
1173 | 1201 | | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
1174 | 1212 | | |
1175 | 1213 | | |
1176 | 1214 | | |
| |||
Lines changed: 69 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
| 172 | + | |
| 173 | + | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | | - | |
181 | | - | |
| 180 | + | |
| 181 | + | |
182 | 182 | | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
187 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| |||
267 | 267 | | |
268 | 268 | | |
269 | 269 | | |
270 | | - | |
271 | | - | |
| 270 | + | |
| 271 | + | |
272 | 272 | | |
273 | | - | |
| 273 | + | |
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
279 | | - | |
| 278 | + | |
| 279 | + | |
280 | 280 | | |
281 | | - | |
282 | | - | |
| 281 | + | |
| 282 | + | |
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
287 | | - | |
288 | | - | |
| 287 | + | |
| 288 | + | |
289 | 289 | | |
290 | 290 | | |
291 | 291 | | |
| |||
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
354 | 359 | | |
355 | 360 | | |
356 | 361 | | |
| |||
488 | 493 | | |
489 | 494 | | |
490 | 495 | | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
491 | 501 | | |
492 | 502 | | |
493 | 503 | | |
| |||
504 | 514 | | |
505 | 515 | | |
506 | 516 | | |
| 517 | + | |
| 518 | + | |
507 | 519 | | |
508 | 520 | | |
509 | 521 | | |
510 | 522 | | |
511 | 523 | | |
| 524 | + | |
512 | 525 | | |
513 | 526 | | |
514 | 527 | | |
| |||
565 | 578 | | |
566 | 579 | | |
567 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
568 | 605 | | |
569 | 606 | | |
570 | 607 | | |
571 | | - | |
572 | | - | |
| 608 | + | |
| 609 | + | |
573 | 610 | | |
574 | 611 | | |
575 | 612 | | |
| |||
630 | 667 | | |
631 | 668 | | |
632 | 669 | | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
633 | 681 | | |
634 | 682 | | |
635 | 683 | | |
| |||
0 commit comments