Files

97 lines
2.8 KiB
TeX

\section{Retry Strategy}
\subsection{Exponential Backoff with Jitter}
Initial retry uses exponential backoff:
\begin{equation}
delay(n) = \min(base \times 2^n + jitter(), max\_delay)
\end{equation}
where:
\begin{itemize}
\item $base = 60$ seconds
\item $max\_delay = 86400$ seconds (24 hours)
\item $jitter() \sim Uniform(0, 0.1 \times delay)$
\end{itemize}
\subsection{Adaptive Retry Algorithm}
We introduce an adaptive algorithm that learns endpoint reliability:
\begin{definition}[Endpoint Health Score]
For endpoint $e$ with recent delivery attempts $\mathcal{D}_e$:
\begin{equation}
health(e) = \frac{\sum_{d \in \mathcal{D}_e} \mathbf{1}[d.success] \cdot decay(d.time)}{|\mathcal{D}_e|}
\end{equation}
where $decay(t) = e^{-\lambda(now - t)}$ with $\lambda = 0.1/hour$.
\end{definition}
\begin{algorithm}
\caption{Adaptive Retry Scheduling}
\begin{algorithmic}[1]
\Function{ScheduleRetry}{$delivery$, $attempt$}
\State $endpoint \gets delivery.subscription.url$
\State $h \gets health(endpoint)$
\State $base\_delay \gets ExponentialBackoff(attempt)$
\If{$h > 0.9$}
\State \Comment{Healthy endpoint: aggressive retry}
\State $delay \gets base\_delay \times 0.5$
\ElsIf{$h > 0.5$}
\State \Comment{Degraded endpoint: standard retry}
\State $delay \gets base\_delay$
\Else
\State \Comment{Unhealthy endpoint: conservative retry}
\State $delay \gets base\_delay \times 2$
\EndIf
\State \Call{EnqueueRetry}{$delivery$, $delay$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\subsection{Retry Schedule}
\begin{table}[h]
\centering
\caption{Retry Schedule (Standard)}
\begin{tabular}{ccc}
\toprule
\textbf{Attempt} & \textbf{Delay} & \textbf{Cumulative Time} \\
\midrule
1 & Immediate & 0 \\
2 & 1 minute & 1 minute \\
3 & 5 minutes & 6 minutes \\
4 & 30 minutes & 36 minutes \\
5 & 2 hours & 2.6 hours \\
6 & 8 hours & 10.6 hours \\
7 & 24 hours & 34.6 hours \\
8 & 48 hours & 82.6 hours \\
\bottomrule
\end{tabular}
\end{table}
After 8 failed attempts (approximately 3.5 days), the delivery moves to the dead letter queue.
\subsection{Delivery Guarantees}
\begin{theorem}[At-Least-Once Delivery]
For any event $e$ and active subscription $s$ with $matches(e, s)$:
\[
P(\text{delivered}(e, s) | \text{endpoint eventually available}) = 1
\]
\end{theorem}
\begin{proof}
Events are durably stored before delivery. Retry continues until success or exhaustion. If the endpoint becomes available within the retry window, delivery succeeds. The probability of 8 consecutive failures with an available endpoint approaches zero given independent attempt outcomes.
\end{proof}
\begin{theorem}[Eventual Delivery Rate]
With endpoint availability $a$ and retry count $n$:
\begin{equation}
P(\text{delivered}) = 1 - (1-a)^n
\end{equation}
For $a = 0.5$ and $n = 8$: $P = 99.6\%$
\end{theorem}