Skip to content

Commit abf0ff6

Browse files
committed
update
1 parent 6cb338b commit abf0ff6

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

youtube/episode1/episode-1.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
> There are three states:
3131
> - **Closed** — everything is normal, requests go through
3232
> - **Open** — failures exceeded the threshold, requests are blocked
33-
> - **Half-Open** — a trial period, one request is allowed through to test recovery
33+
> - **Half-Open** — a trial period, one request is allowed to test recovery
3434
3535
> "This pattern was popularized by Michael Nygard in his 2007 book *Release It!*.
3636
> and Martin Fowler wrote a well-known article about it on his website. If you want to go deeper on the concept, Fowler's article is a great starting point — I'll link it in the description.
@@ -63,13 +63,13 @@ $ganesha = Ackintosh\Ganesha\Builder::withCountStrategy()
6363
->build();
6464
```
6565

66-
> "All right, let me walk through the options:
66+
> All right, the adapter is how Ganesha persists its state. Here I'm using Redis. Ganesha supports multiple storage adapters — Redis and Memcached are the ones I'd recommend."
67+
68+
> "let me walk through the options:
6769
>
6870
> - `failureCountThreshold(3)` — the circuit trips after 3 consecutive failures
6971
> - `intervalToHalfOpen(10)` — 10 seconds after tripping, Ganesha allows one trial request through
7072
>
71-
> Cool. The adapter is how Ganesha persists its state. Here I'm using Redis. Ganesha supports multiple storage adapters — Redis and Memcached are the ones I'd recommend."
72-
7373
---
7474

7575
## Scene 3 — The basic API: `isAvailable()`, `success()`, `failure()`
@@ -130,46 +130,52 @@ var_dump($ganesha->isAvailable($service)); // bool(false)
130130
131131
```php
132132
$ganesha->subscribe(function (string $event, string $service, string $message): void {
133-
error_log(sprintf('[Ganesha] %s: %s', $event, $service));
133+
echo sprintf('%s(%s): %s', $event, $service);
134134
});
135135
```
136136

137-
> "There are three events:
138-
> - `EVENT_TRIPPED` — the circuit just opened
139-
> - `EVENT_CALMED_DOWN` — the circuit recovered and closed again
140-
> - `EVENT_STORAGE_ERROR` — the storage backend had a problem
141-
>
142-
> Cool. And notice that storage errors are handled gracefully — if Redis goes down, Ganesha defaults to returning `true` from `isAvailable()` rather than crashing your application. It fails open, which is usually the right default for a circuit breaker."
137+
> It's a good idea to use different log levels depending on the event type
138+
139+
```php
140+
$ganesha->subscribe(function (string $event, string $service, string $message): void {
141+
switch ($event) {
142+
case \Ackintosh\Ganesha::EVENT_TRIPPED:
143+
echo sprintf('[ERROR] the circuit just opened %s(%s): %s', $event, $service, $message);
144+
case \Ackintosh\Ganesha::EVENT_CALMED_DOWN:
145+
echo sprintf('[INFO] the circuit recovered and closed again %s(%s): %s', $event, $service, $message);
146+
case \Ackintosh\Ganesha::EVENT_STORAGE_ERROR:
147+
echo sprintf('[WARN] the storage backend had a problem %s(%s): %s', $event, $service, $message);
148+
default:
149+
break;
150+
}
151+
});
152+
```
153+
154+
> "All right, let's run it again and confirm that the logs are output as expected."
143155
144156
---
145157

146158
## Scene 6 — Brief mention of the Rate Strategy
147159

148-
> "Okay, I mentioned there's a second strategy — the **Rate strategy**. Instead of counting raw failures, it tracks the failure rate as a percentage over a sliding time window. This is better for high-traffic services where a fixed count doesn't scale well.
160+
> "All right, let me add a quick note about the strategy.
149161
150-
```php
151-
$ganesha = Ackintosh\Ganesha\Builder::withRateStrategy()
152-
->adapter(new Ackintosh\Ganesha\Storage\Adapter\Redis($redis))
153-
->failureRateThreshold(50) // trip if 50% of requests fail
154-
->minimumRequests(10) // but only after at least 10 requests
155-
->timeWindow(30) // measured over a 30-second window
156-
->intervalToHalfOpen(10)
157-
->build();
158-
```
162+
*Open the README, navigate to the Rate strategy.*
163+
164+
> I mentioned there's a second strategy — the **Rate strategy**. Instead of counting failures, it tracks the failure rate as a percentage over a sliding time window. This is better for high-traffic services where a fixed count doesn't scale.
159165
160166
> "All right. We won't go deeper into this today, but the API is identical — same three methods, same event system. Cool."
161167
162168
---
163169

164170
## Scene 7 — Tease for Episode 2
165171

166-
*Open [src/Ganesha/Storage/Adapter/Redis.php](../src/Ganesha/Storage/Adapter/Redis.php), navigate to the `reset()` method.*
167-
168172
> "All right, before I wrap up — let me show you something I found in the codebase."
169173
174+
*Open [src/Ganesha/Storage/Adapter/Redis.php](../src/Ganesha/Storage/Adapter/Redis.php), navigate to the `reset()` method.*
175+
170176
*Scroll to the `reset()` method's TODO comment.*
171177

172-
> "There's a TODO here. The `reset()` method — which is supposed to clear all circuit breaker state — is not implemented for the Redis adapter. If you call `$ganesha->reset()` right now with Redis, nothing happens. All right.
178+
> "There's a TODO here. The `reset()` method — which is supposed to clear all circuit breaker state — is not implemented for the Redis adapter. If you call `$ganesha->reset()` right now with Redis, nothing happens.
173179
>
174180
> So in the next video, I'm going to fix this. We'll look at how Redis is storing Ganesha's data, figure out the right approach to delete it all safely, write the implementation, and test it.
175181
>

0 commit comments

Comments
 (0)