<h3>What I'm Trying To Do</h3>
<p>I'm trying to make a deployment and watch for k8s events until the deployment is ready using <strong>k8s node api</strong> (Watch): <a href="https://github.com/kubernetes-client/javascript/blob/master/examples/typescript/watch/watch-example.ts" rel="noreferrer">https://github.com/kubernetes-client/javascript/blob/master/examples/typescript/watch/watch-example.ts</a></p>
<hr />
<h3>My Questions</h3>
<p>I have read this section: <a href="https://kubernetes.io/docs/reference/using-api/api-concepts/#watch-bookmarks" rel="noreferrer">https://kubernetes.io/docs/reference/using-api/api-concepts/#watch-bookmarks</a> over and over but I still can't understand, <strong>from the client perspective</strong>:</p>
<ol>
<li>What is this feature try to solve?</li>
<li>When should I use it?</li>
<li>Can I not use it and not miss events?</li>
<li>How do I use it?</li>
<li>What should I do when I receive bookmark event.</li>
</ol>

Stav Alfi
<p>I'll attempt to answer your questions from the client's perspective:</p>
<h2>What is this feature trying to solve? </h2>
<p>Its intended to reduce the load on kube-apiserver from clients that issue Watch requests for a resource type. Bookmarks are intended to let the client know that the server has sent the client all events up to the <code>resourceVersion</code> specified in the Bookmark event. This is to make sure that if the watch on the client side fails or the channel closes (after timeout), the client can resume the watch from <code>resourceVersion</code> last returned in the Bookmark event. It's more like a checkpoint event in the absence of real mutating events like Added, Modified, Deleted.</p>
<p>The client could already be caching the resourceVersion that is received as part of the regular Added, Modified, Deleted events, but consider a case where the resource you're watching has had no updates in the last 30 minutes and the <code>resourceVersion</code> you have cached is &quot;100&quot;.
 </p>
<p>In the absence of bookmark events, you will attempt to resume from &quot;100&quot;, but the server could return a &quot;410 Gone&quot; indicating that it doesn't have that version or it is too old. In that case, the client will have to do a List to get the latest resourceVersion and initiate a watch from there or start the watch from latest by specifying no resourceVersion, which is more expensive for the server to process.</p>
<p>In the presence of bookmark events, the server might attempt to send you a Bookmark event with resourceVersion &quot;150&quot; indicating that you have processed up that version and in the event of a restart you can start processing from there onwards.
 
This contrived example in the documentation shows just that. You start your watcher at rv=&quot;10245&quot;, you process some events up to rv=&quot;10596&quot; and then the server sends you a bookmark with rv=&quot;12746&quot; so in the event of a restart you can start processing from there onwards.</p>
<pre><code>GET /api/v1/namespaces/test/pods?watch=1&amp;resourceVersion=10245&amp;allowWatchBookmarks=true
---

200 OK 
Transfer-Encoding: chunked 
Content-Type: application/json

{
  &quot;type&quot;: &quot;ADDED&quot;,
  &quot;object&quot;: {&quot;kind&quot;: &quot;Pod&quot;, &quot;apiVersion&quot;: &quot;v1&quot;, &quot;metadata&quot;: {&quot;resourceVersion&quot;: &quot;10596&quot;, ...}, ...}
}
...
{
  &quot;type&quot;: &quot;BOOKMARK&quot;,
  &quot;object&quot;: {&quot;kind&quot;: &quot;Pod&quot;, &quot;apiVersion&quot;: &quot;v1&quot;, &quot;metadata&quot;: {&quot;resourceVersion&quot;: &quot;12746&quot;} }
}
</code></pre>
<h2>When should I use it?</h2>
<p>For efficient processing of change events on the resource your watching, it seems better to process Bookmarks than to not. There are no guarantees round the delivery of Bookmarks though - the server might not support it (if it is running an older version of Kubernetes), or it might not send them at all.</p>
<h2>Can I not use and not miss events?</h2>
<p>Yes, you could totally do that, but your likelihood of missing events decreases if you use Bookmarks. Also remember that it not only benefits the client but also the kube-apiserver, because it could return events from its local cache if it has the &quot;fresh&quot; resourceVerion you received in a Bookmark, in the absence of which it will have to do a consistent-read from etcd. I recommend <a href="https://www.youtube.com/watch?v=PLSDvFjR9HY" rel="noreferrer">this</a> video to understand how Watch events work under the hood.</p>
<h2>How do I use it?</h2>
<p>Depending on which client library you're suing the usage might be different, but in a raw HTTP request you can specify this query param: <strong>allowWatchBookmarks=true</strong></p>
<pre><code>GET /api/v1/namespaces/test/pods?watch=1&amp;resourceVersion=10245&amp;allowWatchBookmarks=true
</code></pre>
<p>If you're using <a href="https://github.com/kubernetes/client-go" rel="noreferrer">client-go</a>, there is a tool called Reflector, and <a href="https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go#L409" rel="noreferrer">this</a> is how it requests bookmarks and <a href="https://github.com/kubernetes/client-go/blob/master/tools/cache/reflector.go#L518" rel="noreferrer">this</a> is how it processes it.</p>
<h2>What should I do when I receive a Bookmark event?</h2>
<p>Extract the resourceVersion from the Bookmark event and cache it for when you try to restart your watcher for any reason.</p>
