Adding Self-Discovery to Client Code
As I'm getting ready to move into the "full-up" mode of my Greeks Service, I realize that my client library really needs to auto-discover the servers it can talk to, and certainly, the non-C++ clients need to have an easy way to find out what's hosted where. Given that I really don't want the clients to have to hit something like a mongoDB database and parse the document to get the range, it made a lot more sense to build the discovery into the services themselves. After all, they are going to have to read their configuration from the mongoDB-backed configuration service in The Broker, so it makes sense that if they are already up and going, it should be very easy to have them respond to simple requests for what they cover.
So the first thing to do was to add a "coverage" request/response to the application. This would respond with a list of two strings - the beginning of the covered range, and the end of the covered range. These are obtained from the OPRA channels that we're getting data from, and it's also the filtering criteria on what options to load in from the data master database of instrument data.
This was really simple because there's no need for any security on this call, and it's the only 'call' (aka 'one shot') that the service handles. Pretty simple. With this, the C++ client can then ask The Broker what services it knows about, filtering out based on a very simple pattern match to find the ones that are for my Greek Engine, and then ask each for their coverage. It then builds up the map and it's then easy for the client to know who to dispatch the request to. Nice.
But that's not the end of the story. I also wanted to make it possible to have a client ask a service where to go. This is a very simple service that does basically the same thing, but if we have one per Greek Engine service, then The Broker can load-balance between them, and each will know it's own engine's coverage quickly and easily, and it can repeat the process the client code uses to find out all the others. Once it's got this data cached, it's fast.
The upside is that we have a simple "piggy back" service on each Greek Engine that can locate any symbol or family very quickly. This means that if a web sockets client needs to know who to talk to, they can his this locator service, ask it, get the service name, and then talk to it. Pretty nice.
With this, I've got a pretty nice self-discovery system in place. I could add it to my Ticker Plants too, but I'm not so sure they will benefit as much from it. They broadcast on ZeroMQ reliable multicast channels, and the client is the only way to get to that data. So it's not as big a deal. But it's a nice solution, and I can think about it for later.