educative.io

Educative

What's the detailed sequence flow of the Key Generation Service?

A picture is a 1000 words and hopefully we could get a detailed sequence diagram to demonstrate how the Key Generation Service works. The description like this “As soon as KGS gives some keys to an application server, it can move these to the used keys table.” is quite vague: what’s the actual sequence? When KGS fetches some unused keys, should it add them to the used keys table before returning to the application server? If it returns to the application server and fails to write to the used keys table, we would use the same keys again in the future, right? The term “as soon as” does not exactly tell us what’s happening.

1 Like

Hi, here what I understood,

There are some cases but lets discuss two of them, if you put a cache in the KGS and if you do not.

KGS with cache:
Initially and internally the KGS service get a bunch of keys in the no-used table and fill the cache, all those keys are marked as used, this is done periodically inside the KGS service.

When an external service hits KGS the cache return a key and this is removed from the cache, if the caller goes down and crash the key is lost but that is ok.

KGS no cache:
In this scenario when an external service hits KGS you retrive a key from the no-used table, put that key in the used table and then return the key, if the caller crash the key is lost but that is ok because the number of keys is big enough.

I agree with your description. We can even elaborate it a little bit more: when we “put that key in the used table”, if some keys already existing in the table, we don’t return those keys to the caller. I just don’t like how the course says “As soon as KGS gives some keys to an application server, it can move these to the used keys table.” and it’s very misleading.