Using Service Discovery to build dynamic python applications
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this
Jacob, Alexys
Alexys Jacob - Using Service Discovery to build dynamic python applications Let's compare the usage of three major **service discovery** technologies to build a dynamic and distributed python application ! This talk will be about **consul**, **etcd** and **zookeeper** and their python bindings and will feature code along with a live demo. - This talk will **showcase and compare** three Service Discovery technologies and their usage to **build a dynamic and distributed python application** : - consul - etcd - zookeeper After a short introduction to service discovery, we will **iterate and compare** how we can address the concrete and somewhat complex design of our python application using each technology. We'll then be able to discuss their strengths, weaknesses and python bindings and finally showcase the application in a demo.
 Let's go. Okay, so we're gonna talk about service discovery today and We'll focus on the The client side how do you use service discovery and Python? and I won't argue if you should or not use this service discovery in this talk I won't explain how to install the three technologies that we I will cover here I will just focus on their usage and If we have time which I hope we will have I'm crazy enough to have done a live demo So we will try it It's an opinionated torque, okay, so That's my point of view here Short introduction about me you can find me on the nick ultra bug Gentoo Linux developer where I work mostly on cluster stuff and Python stuff. I maintain packages Related to no sequel kill the key value stores or a message to him I'm also CTO and number Lee We are programmatic and data driven marketing and advertising company We have a booth over there with a quiz and you can win some crazy stuff So just come around and you can have a talk Okay, so what is service discovery? To make it short you can compare it to what DNS is for your browser But in a dynamic way when you connect to a website your browser First half to find out the IP address of the host hosting the website you want to reach and to do so It does a DNS query Before hand when you're you own the website the web service And the website you had to configure the DNS and Register inside the IP address of the server of your server Service discovery is about the same thing. It's about registering and querying but for service That's the basic of it Let's see a bit more about it. So We have a catalog that's provided by the service discovery technologies and Then you have your servers Each of them provide a service some of them provide the same service They will register themselves into the catalog and So you will get a list of service is running at host and port multiple times if the service is running on multiple servers Then you have clients The clients will be looking for a service by its name usually and they will query the catalog For the given service and they will be handed over a list of available hosts providing set service This is service discovery Now let's take a quick tour of the three technologies I will cover here The first one is the oldest one. It's named zookeeper. It's from the Hapash Foundation and Zookeeper is Firstly designed as a reliable cluster coordination. It's used mostly and mainly in Hadoop It has some pretty interesting features and it's mature since it's the oldest of the three technologies we cover here When I say in the negative points that it doesn't provide service discovery per se, that's true But we'll get back to it later as to how we can still use zookeeper To to you to achieve service discovery what I mean by this is that it's not a built-in feature of zookeeper The main design of zookeeper and it's the same for ETCD Which we'll see just after this is that you can compare them to a distributed hierarchical file system Which is also comparable to a key value store. You'll see about it and It's pretty Java and It uses a special implementation for consensus algorithm The consensus is about making sure all the nodes of the zookeeper cluster agree on something The Python C bindings are not usable There is one provided here on the on the sources, but it's not really usable and even worse for service discovery It's not a data center aware Technology it just knows about its own cluster Now you have ETCD, ETCD is from the CoreS guys It's pretty recent project. It's written in Go. It uses the raft consensus Which is pretty robust It has a good adoption. It's used on many big bigger projects Like Kubernetes and it provides an HTTP API to do older queries and registration stuff It's pretty simple really simple to implement and configure Just like zookeeper it doesn't provide per se a service discovery mechanism But we will use the file system hierarchy to achieve this It's not that a centerware either and it doesn't provide any kind of health checking of your services once you register. We'll see about it later as well The third one is console is from HashiCorp. That's the newest of the three It's also written in Go. It's also using the raft consensus algorithm and Yeah, I told you it's an opinionated torque. So I didn't find any bad things to say about it Because it has built-in service discovery Feature it's data center aware so you can have multiple clusters of consoles in each data center and they can talk about them between them and It also provides a DNS API so you can also look up for services using DNS Which is kind of a good feature The note I wanted to stress out on zookeeper and ETCD is that we will achieve services discovery by abusing the key value store You can see the key value store are the sort of file system where you can sort store data Registering is about creating a node or a folder or a file if you want to relate it to your local file system and Make it meaningful In this kind of example at the root of the hierarchy I will say okay the first level is will be my service name API X Then on the second level I will create a folder which will represent all the service all the servers providing this service So I call this folder providers and then inside I will create nodes or you can relate it to files Which are named my host two points and the port so discovering providers for API X service is just like Listing the content of API X slash providers directory fine We can do the same with memcache and stuff like that. That's how you can abuse and Achieve at service discovery using key value store based technologies such as the keeper and ETCD Okay Okay, now let's see the Python Client's library to talk to each of those technologies the first one in zoo keeper is Kizoo ZZK and Yeah, I know I'm sorry about this. We can be very very creative community. I know and We'll use the underscore line One ZZK which under like underneath uses Kizoo So you can see a rapper ZZK as a service discovery oriented wrap wrapper of of Kizoo So it's pretty pretty handy Then for a TCD we have some standard Python dash ETCD library, which is pretty good If you use async.io you have another for a think I have stuff as well and for console You have consulate and Python console We'll use Python console which is more Now documented and more active than consulate last year it was the contrary but This year Python console is very very nicely implemented now. So good job guys. Thank you Okay When you choose a technology you have to rely on it even more when it will be the core of your whole topology and You have to make sure that you can rely on the Python clients Because they really really have a direct impact on your application So let's see about the ZZK client library which uses Kizoo When you wanted to connect to a zookeeper cluster you can specify multiple hosts Which is pretty cool It has rotary connect feature you can query about the connection state you will get connected or Disconnected and stuff like that so you can have your code Handle this gracefully And it has rich accept exceptions if something wrongs happen. So I'm providing a quick example here The don't fail on connect means if No server is available when I do the first line and wait and try to connect to to my zookeeper cluster Will it be blocking will it raise an exception in this case? It's blocking If you and you can change this with the weight Parameter, but it will raise an exception Okay, so need so it's not for the one of you who are used to the Python memcached library You have to know about this and handle it Because it's can block your whole application if no zookeeper server is up On the ETCD side Python and ETCD side You don't have the possibility to connect to multiple hosts But you have a total reconnection gracefully, so it's pretty good. You can't really Try and get the connection states the exception as are pretty rich So you can see what's happening pretty easily and catch the good exceptions about the different kind of errors that you can happen to to be running into and It does fail on connect The Python console one is Well Not so good as this ZCZK one as well because doesn't support multiple hosts either He tasks or reconnect feature auto reconnect feature you The exceptions are so so I'm providing an example here connection error is well sometime not very very meaningful But it doesn't fail on connect that means it's non-blocking you just Create your console Client and then continue on Nothing happens when you do that Which can be a good feature Okay, now about the service registration There are three things you have to consider here three states of a service life cycle is getting up and he needs to register into the catalog Then it's running and you have to make sure it's still running Because if it's not running it crashes or your server Providing set service becomes unavailable. You don't want to answer clients about it Okay, so you have to remove it in a way from the catalog when it's down That's the dynamic part and Then if we stop gracefully of or if we crash we have to derogist it from the catalog So the health checking will also do the derogistration for you in in case of failure we'll see How it's done on every Python implementation For the CZC ZK It's pretty straightforward the main line The main thing to understand is the first one over here and the first try accept will just create The file system hierarchy. I talked to you about so we just make sure that we have the slash EP 2016 providers and we do a make path which will create the whole path like MK dear dash P and If the node already exists, it's okay. We can we can continue then the ZCZK provides Cool method which is register and then you say okay on this node on the provider's node I will register a machine named Yaz running on power port 5000 And it will create the the file like node like he has two points 5000 for you Okay That's all we have to do Now about health checking The health checking in zookeeper is implicit because the keeper has this cool feature named ephemeral nodes ephemeral nodes. It just like That they are like Files or nodes in the file system hierarchy that are present on the file system as long as the As long as the session of the client who created them is alive so whenever you the client dies or Closes its session zookeeper will know about it and we remove the given node Automatically So it's a good way of doing health checking because if your application crashes or You want just to do register you just have to Exit gracefully and close your session by closing the session to zookeeper zookeeper will remove all the nodes you created with this application So the register thing does that it creates an ephemeral node So that's implicit in the ZCZK Python client What about the failure detection latency if my program is Kill-9 or crashes badly and didn't have time to register gracefully How long will it take for zookeeper to remove the node from the hierarchy and then In other words, how long will I really take for the clients to not be serve? my host and port anymore it Will take session time out here when I created my client session I said five so it will take up to five seconds in this case To make this happen So for five seconds maximum, I could be serving wrong host and port to my clients from the catalog That's something you have to consider as well in such topologies on It's basically the same principle We try to read the provider if we can't find it recreate it as a directory Then we just have to write there is no register wrapper or something like this So you we just have to write the given Node I'll talk to you about here and we can set the data in it So we put also the same thing in the value. It's not a directory and it has a time to leave TTL Which I've talked to you right now That's the health checking actually You can see that it's coming difficult here, why? Because it is he doesn't have the concept of Ephemeral nodes as the keeper has that means that you have it to implement health checking yourself or use a third-party library or program to do it for you But you have to do it yourself. So in this example, I'm doing it myself So the trick I'm using is have is that when my application start I have to create a health finger thread Which will constantly and in infinite loop register my service and that will be a sort of heartbeat or health checking stuff with a TTL and then my TTL the time to leave of the node. I'm creating it will be removed after X second TTL seconds from the hierarchy. So my fellow detection latency is TTL But I have to have a thread constantly Making sure that my node is present and so my service and server is in the catalog Okay If you use console Everything is granted and built in so you can see in the code that's it's pretty straightforward and I just have to Register my service into a console agent which is as well very self-explanatory The name of the service the address of the host providing it and the port is running on the console. It's integrated nothing more to have The health checking is interesting in console because you have a way To Make sure that the console servers will run some health checks of your service by themselves So you just have to create like in my example, it's an HTTP service So I'm creating an object a health check object which is of kind HTTP and I'm providing the URL that the console server should Call every two seconds. So I'm telling console a okay and when I register I pass the extra argument check and I I said to console. Okay. Check this URL every two seconds if it fails remove me from the catalog or To be very correct mark me as failing All right How do you discover all of this? It's pretty straightforward as well and And so I will just show you the querying part For zookeeper You can get the addresses by listing the children of the given node so I'm listing the children of the providers folder in EP 2016 and That will be my notes. I Just have to look over them split the two points and And I get the host and port of every server providing my service Okay Etcd basically the same stuff So you make a recursive query read you get the children and you split and you get your host and port On console It's also very easy you query the health service because you want only to get the healthy servers providing your service So that's the passing Equals through here. I just want you to return the service Where the health check is passing the servers and ports for which the server the health check is passing. Okay, and Then inside I get a lot of information It's a directory style thing and inside there is the host port and other stuff interesting stuff Sounds good, okay Now let's play so I have given three Raspberry pies and my machine here is running a zookeeper Etcd and console agent so The idea I had is to showcase a service discovery page like this Where we will be looking for the EP? 2016 host providing the We'll be looking for the host providing the EP 2016 Service so I Just wanted also to to demonstrate Yeah, okay, that's my Okay, it's here to demonstrate the key value Storage which he all those technologies are also used to configuration Access so you can store your configuration in this Key value stores so your application can also get them from from it. So the color here I don't know if it's really all Because of the resolution. Yeah Every time I reload this I Change the color Configured on each and in zookeeper in Etcd and in console for my for my web service so dick, can you start running your? your Raspberry Pi so raspberry pi 4 is this one that I plugged in a few seconds before and I can just go to it like this and You can see That every time that I will change the color on the key value store it will be picked up by the application from in this case zookeeper and then dick just plugged in the raspberry pi number one Which appeared and got discovered here by the server on every platform so if you can you also plug in yours and You too so we'll see the others coming and What's interesting? About this is like this Okay It's gonna get hot now. I think my raspberry pi 4 Gets a bit overloaded here. That's the Wi-Fi, but it's okay So it's time. I reload Okay, dear raspberry pi is running pretty awesome You see that my raspberry pi 4 which is not responding here You can see that it's not responding the health check failed for every one of them and that's it's has been removed from Zookeeper etcd and console So it's a good thing. Okay, it's working right Okay, so now we can see raspberry pi 2. Okay raspberry pi 4 is Getting back somehow You can't yeah, it's a bit is getting back Yeah, it's getting back. Okay Raspberry pi 3 on console. Yeah, it's working as well. Okay You can see the not yet the color now. All right Yeah So now we have the four raspberry pies happen running and They seem to be yeah pretty stable on the health check. Yeah, I Will remove I will disconnect raspberry pi 4 Now let's see about the time it takes it depends on the technology Because they have a different kind of TTL FMR node session timeout or health check timeout. Okay? All right, it's Yeah, some of them are overloaded. Do you have any question? Yeah, I don't know Yeah, yeah, yeah Yeah, the client decides so the question is if there any kind of balancing no the catalog in the when your client queries the catalog It gets a list of all the available nodes for the given service That's all that then it's up to you to decide to which one you want to connect Yeah, I have a question about redundancy if you have an application that is dependent on the service discovery catalog and For different services that that Exposes and the catalog for some reason crashes. How will you? Recover from that situation will you have like service discovery of the service discovery or? How would you do that? Yeah? No, you don't do services cover your services discovery the minimum that's Advise of servers is three so you should have at least three zookeeper or console servers running Okay, so if you want more resiliency make fuck make it five seven but an uneven number. Okay, always an even number If something very bad happens and you don't have service discovery anymore, I Guess you have to Handle it on your application side. You can make it like with cash caching stuff It's not it's not very easy and it really depends on the type of application you're running But the best best course is to make sure your services discovery cluster Has enough nodes to sustain this kind of problem Well, it depends on the technology actually as you saw if you use a keeper you can connect to multiple hosts So you don't need a load balancer just but every of the node in this on the other hand in Console and each cd you have to specify one of those on one of the nodes So maybe you can implement some kind of stuff on your application to handle this Like having a dq or something like this in python and try again in each Exception if you it's it's raises an exception you can try and connect to the other host etc etc Yeah I think for the recording sorry a Question about registration procedure. Yeah, why don't you want to use external tool to do this it can be Implemented in configuration management chief puppet salt And in this case you will have possibility to register Sort by the services like MongoDB and so on automatically So That's question why not do this as external service for your application? well Hmm, I think To me chef and stuff like that are good for provisioning or configuration really configuration Applying configuration to servers. I don't see service discovery like this to me is I relate to your point with MongoDB and and and Demand stuff like this You have external programs that do it for you I'm not sure that For instance chef etc can have have checks running on So if you make with with ETCD it may become difficult to do There are a lot of third parties libraries doing it for ETCD for example because it has a wide audience and For containers stuff like this They they use specific third party tools, but not provisioning tools Yeah, we are using register container that register container that automatically registers any container that is running on Docker host and it's it's very Good idea. I think it's yeah, it works well and it's if something happens with container it will be there just automatically Yeah, but it has to be registered somewhere anyway Yeah, we are running local agent on each host machine local consulate agent and each service knows that it can find agent on local host and Engine only agent knows where there is a console cluster located It's can be implemented in very easy way. Yeah, but you don't have Central configuration place or you you do it also in them We are using salt to to install everything, but actually a service discovery is Implemented using special containers. Okay No other question Well, thank you. I
 Let's go.  Okay, so we're gonna talk about service discovery today and  We'll focus on the  The client side how do you use service discovery and Python?  and I won't argue if you should or not use this service discovery in this talk  I won't explain how to install the three technologies that we I will cover here  I will just focus on their usage and  If we have time which I hope we will have  I'm crazy enough to have done a live demo  So we will try it  It's an opinionated torque, okay, so  That's my point of view here  Short introduction about me you can find me on the nick ultra bug  Gentoo Linux developer where I work mostly on cluster stuff and Python stuff. I  maintain packages  Related to no sequel kill the key value stores or a message to him  I'm also CTO and number Lee  We are programmatic and data driven marketing and advertising company  We have a booth over there with a quiz and you can win some crazy stuff  So just come around and you can have a talk  Okay, so what is service discovery?  To make it short you can compare it to what DNS is for your browser  But in a dynamic way when you connect to a website your browser  First half to find out the IP address of the host hosting the website you want to reach and to do so  It does a DNS query  Before hand when you're you own the website the web service  And the website you had to configure the DNS and  Register inside the IP address of the server of your server  Service discovery is about the same thing. It's about registering and querying but for service  That's the basic of it  Let's see a bit more about it. So  We have a catalog that's provided by the service  discovery technologies and  Then you have your servers  Each of them provide a service some of them provide the same service  They will register themselves  into the catalog and  So you will get a list of service is running at host and port  multiple times if the service is running on multiple servers  Then you have clients  The clients will be looking for a service by its name usually and they will query the catalog  For the given service and they will be handed over a list of available hosts  providing set service  This is service discovery  Now let's take a quick tour of the three technologies I will cover here  The first one is the oldest one. It's named zookeeper. It's from the Hapash Foundation and  Zookeeper is  Firstly designed as a reliable cluster coordination. It's used mostly and mainly in Hadoop  It has some  pretty interesting features and it's mature since it's the oldest of the three technologies we cover here  When I say in the negative points that it doesn't provide service discovery per se, that's true  But we'll get back to it later as to how we can still use zookeeper  To to you to achieve service discovery what I mean by this is that it's not a built-in feature of zookeeper  The main design of zookeeper and it's the same for ETCD  Which we'll see just after this is that you can compare them to a distributed hierarchical file system  Which is also comparable to a key value store. You'll see about it and  It's pretty Java and  It uses a special implementation for consensus algorithm  The consensus is about making sure all the nodes of the zookeeper cluster agree on something  The Python C bindings are not usable  There is one provided here on the on the sources, but it's not really usable and even worse for service discovery  It's not a data center aware  Technology it just knows about its own cluster  Now you have ETCD, ETCD is from the CoreS guys  It's pretty recent project. It's written in Go. It uses the raft consensus  Which is pretty robust  It has a good adoption. It's used on many  big bigger projects  Like Kubernetes and it provides an HTTP API to do older queries and registration stuff  It's pretty simple really simple to implement and configure  Just like zookeeper it doesn't provide per se a service discovery mechanism  But we will use the file system hierarchy to achieve this  It's not that a centerware either and it doesn't provide any kind of  health checking of your services once you register. We'll see about it later as well  The third one is console is from HashiCorp. That's the newest of the three  It's also written in Go. It's also using the raft consensus  algorithm and  Yeah, I told you it's an opinionated torque. So I didn't find any bad things to say about it  Because it has built-in service discovery  Feature it's data center aware so you can have multiple clusters of consoles in each data center and they can talk about them  between them and  It also provides a DNS API so you can also look up for services using DNS  Which is kind of a good feature  The note I wanted to stress out on zookeeper and ETCD is that we will achieve services discovery by  abusing the key value store  You can see the key value store are the sort of file system where you can sort store data  Registering is about creating a node or a folder or a file if you want to relate it to your local file system and  Make it meaningful  In this kind of example at the root of the hierarchy  I will say okay the first level is will be my service name  API X  Then on the second level I will create a folder which will represent all the service all the servers providing  this service  So I call this folder providers and then inside I will create nodes or you can relate it to files  Which are named my host two points and the port  so  discovering providers for API X service is just like  Listing the content of API X  slash providers  directory  fine  We can do the same with memcache and stuff like that. That's how you can abuse and  Achieve at service discovery using key value store based technologies  such as the keeper and ETCD  Okay  Okay, now let's see the Python Client's library to talk to each of those technologies the first one in zoo  keeper is  Kizoo ZZK and  Yeah, I know  I'm sorry about this. We can be very very creative community. I know and  We'll use the underscore line  One ZZK which under like underneath uses Kizoo  So you can see a rapper ZZK as a service discovery oriented wrap wrapper of  of Kizoo  So it's pretty pretty handy  Then for a TCD we have some standard Python dash ETCD library, which is pretty good  If you use async.io you have another for a think I have stuff as well and for console  You have consulate and Python console  We'll use Python console which is more  Now documented and more active than consulate last year  it was the contrary but  This year Python console is very very nicely implemented now. So good job guys. Thank you  Okay  When you choose a technology you have to rely on it  even more when it will be the core of your whole topology and  You have to make sure that you can rely on the Python clients  Because they really really have a direct impact on your application  So let's see about the ZZK client library which uses Kizoo  When you wanted to connect to a zookeeper cluster you can specify multiple hosts  Which is pretty cool  It has rotary connect feature you can query about the connection state you will get connected or  Disconnected and stuff like that so you can have your code  Handle this gracefully  And it has rich accept exceptions if something wrongs happen. So I'm providing a quick example here  The don't fail on connect means if  No server is available when I do the first line and wait and try to connect to to my zookeeper cluster  Will it be blocking will it raise an exception in this case? It's blocking  If you and you can change this with the weight  Parameter, but it will raise an exception  Okay, so need so it's not for the one of you who are used to the Python memcached  library  You have to know about this and handle it  Because it's can block your whole application if no zookeeper server is up  On the ETCD side Python and ETCD side  You don't have the possibility to connect to multiple hosts  But you have a total reconnection gracefully, so it's pretty good. You can't really  Try and get the connection states the exception as are pretty rich  So you can see what's happening pretty easily and catch the good exceptions  about the different kind of errors that you can happen to to be running into and  It does fail on connect  The Python console one is  Well  Not so good as this ZCZK one as well because doesn't support multiple hosts either  He tasks or reconnect feature auto reconnect feature you  The exceptions are so so  I'm providing an example here connection error is well sometime not very very  meaningful  But it doesn't fail on connect that means it's non-blocking you just  Create your console  Client and then continue on  Nothing happens when you do that  Which can be a good feature  Okay, now about the service registration  There are three things you have to consider here  three states of a service life cycle is getting up and he needs to register into the catalog  Then it's running and you have to make sure it's still running  Because if it's not running it crashes or your server  Providing set service becomes unavailable. You don't want to answer clients about it  Okay, so you have to remove it in a way from the catalog when it's down  That's the dynamic part  and  Then if we stop gracefully of or if we crash we have to derogist it from the catalog  So the health checking will also do the derogistration for you  in in case of failure  we'll see  How it's done on every  Python implementation  For the CZC ZK  It's  pretty straightforward  the main line  The main thing to understand is the first one over here and the first try accept will just create  The file system hierarchy. I talked to you about  so we just make sure that we have the slash EP  2016 providers and we do a make path which will create the whole path like MK dear  dash P and  If the node already exists, it's okay. We can we can continue then the ZCZK provides  Cool method which is register and then you say okay on this node on the provider's node  I will register a machine named Yaz running on power port  5000  And it will create the the file like  node like he has two points  5000 for you  Okay  That's all we have to do  Now  about health checking  The health checking in zookeeper is implicit because the keeper has this cool feature named ephemeral nodes  ephemeral nodes. It just like  That they are like  Files or nodes in the file system hierarchy that are present on the file system as long as the  As long as the session of the client who created them is alive  so whenever you the client dies or  Closes its session zookeeper will know about it and we remove the given node  Automatically  So it's a good way of doing health checking because if your application crashes or  You want just to do register you just have to  Exit gracefully and close your session by closing the session to zookeeper zookeeper will remove all the nodes you created  with this application  So the register thing does that it creates an ephemeral node  So that's implicit in the ZCZK  Python client  What about the failure detection latency if my program is  Kill-9 or crashes badly and didn't have time to register gracefully  How long will it take for zookeeper to remove the node from the hierarchy and then  In other words, how long will I really take for the clients to not be serve?  my host and port anymore it  Will take session time out here when I created my client session  I said five so it will take up to five seconds in this case  To make this happen  So for five seconds maximum, I could be serving wrong host and port to my clients from the catalog  That's something you have to consider as well in such topologies  on  It's basically the same principle  We try to read the provider if we can't find it recreate it as a directory  Then we just have to write there is no register wrapper or something like this  So you we just have to write the given  Node I'll talk to you about here and we can set the data in it  So we put also the same thing in the value. It's not a directory and it has a time to leave TTL  Which I've talked to you right now  That's the health checking  actually  You can see that it's coming  difficult here, why?  Because it is he doesn't have the concept of  Ephemeral nodes as the keeper has that means that you have it to implement health checking yourself or use a third-party  library or program to do it for you  But you have to do it yourself. So in this example, I'm doing it myself  So the trick I'm using is have is that when my application start I have to create a  health finger thread  Which will constantly and in infinite loop  register my service and that will be a sort of heartbeat or health checking stuff  with a TTL and then my TTL the time to leave of the node. I'm creating it will be removed after  X second TTL seconds from the hierarchy. So my fellow detection latency is TTL  But I have to have a thread constantly  Making sure that my node is present and so my service and server is in the catalog  Okay  If you use console  Everything is granted and built in so you can see in the code that's it's pretty straightforward  and I just have to  Register my service into a console agent which is  as well very  self-explanatory  The name of the service the address of the host providing it and the port is running on  the console. It's integrated nothing more to have  The health checking is interesting in console because you have a way  To  Make sure that the console servers will run some health checks of your service by themselves  So you just have to create like in my example, it's an HTTP service  So I'm creating an object a health check object which is of kind HTTP and  I'm providing the URL that the console server should  Call every two seconds. So I'm telling console a okay and when I register  I pass the extra argument check and I  I said to console. Okay. Check this URL every two seconds if it fails remove me from the catalog or  To be very correct mark me as failing  All right  How do you discover all of this?  It's pretty straightforward as well and  And so I will just show you the querying part  For zookeeper  You can get the addresses by listing the children of the given node  so I'm listing the children of the  providers folder in EP  2016 and  That will be my notes. I  Just have to look over them  split the two points and  And I get the host and port of every server  providing my service  Okay  Etcd  basically the same stuff  So you make a recursive query read you get the children and you split and you get your host and port  On console  It's also very easy you query the health service because you want only to get the healthy  servers providing your service  So that's the passing  Equals through here. I just want you to return the service  Where the health check is passing the servers and ports for which the server the health check is passing. Okay, and  Then inside I get a lot of information  It's a directory style thing and inside there is the host port and other stuff interesting stuff  Sounds good, okay  Now let's play  so I  have given three  Raspberry pies and my machine here is running a zookeeper  Etcd and console agent  so  The idea I had is to showcase a service discovery page like this  Where we will be looking for the EP?  2016  host  providing the  We'll be looking for the host providing the EP 2016  Service so I  Just wanted also to to demonstrate  Yeah, okay, that's my  Okay, it's here to demonstrate the key value  Storage which he all those technologies are also used to configuration  Access so you can store your configuration in this  Key value stores so your application can also get them from from it. So the color here  I don't know if it's really all  Because of the resolution. Yeah  Every time I reload this I  Change the color  Configured on each and in zookeeper in Etcd and in console for my for my web service  so dick, can you start running your?  your  Raspberry Pi so raspberry pi 4 is this one that I plugged in a few seconds before and I can just go  to it like this and  You can see  That every time that I will change the color on  the key value store it will be picked up by  the application from in this case zookeeper and then dick just plugged in the raspberry pi number one  Which appeared and got discovered here by the server on every  platform so if you can you also  plug in yours and  You too so we'll see the others coming and  What's interesting?  About this is like this  Okay  It's gonna get hot now. I think my raspberry pi 4  Gets a bit overloaded here. That's the Wi-Fi, but it's okay  So it's time. I reload  Okay, dear raspberry pi is running pretty awesome  You see that my raspberry pi 4 which is not responding here  You can see that it's not responding the health check  failed for every one of them and that's it's has been removed from  Zookeeper etcd and console  So it's a good thing. Okay, it's working  right  Okay, so now we can see raspberry pi 2. Okay raspberry pi 4 is  Getting back  somehow  You can't yeah, it's a bit is getting back  Yeah, it's getting back. Okay  Raspberry pi 3 on console. Yeah, it's working as well. Okay  You can see the not yet the color now. All right  Yeah  So now we have the four raspberry pies happen running and  They seem to be yeah pretty stable on the health check. Yeah, I  Will remove I will disconnect raspberry pi 4 Now let's see about the time it takes it depends on the technology  Because they have a different kind of  TTL  FMR node session timeout or health check timeout. Okay?  All right, it's  Yeah, some of them are overloaded. Do you have any question?  Yeah, I don't know  Yeah, yeah, yeah  Yeah, the client decides so the question is if there any kind of balancing no the catalog in the when your client queries the catalog  It gets a list of all the available nodes for the given service  That's all that then it's up to you to decide to which one you want to connect  Yeah, I have a question about redundancy if you have an application that is dependent on the service discovery catalog and  For different services that that  Exposes and the catalog for some reason crashes. How will you?  Recover from that situation will you have like service discovery of the service discovery or?  How would you do that? Yeah?  No, you don't do services cover your services discovery the minimum that's  Advise of servers is three so you should have at least three zookeeper or console servers running  Okay, so if you want more resiliency make fuck make it five seven but an uneven number. Okay, always an even number  If something very bad happens and you don't have service discovery anymore, I  Guess you have to  Handle it on your application side. You can make it like with cash caching stuff  It's not it's not very easy and it really depends on the type of application you're running  But the best best course is to make sure your  services discovery cluster  Has enough nodes to sustain this kind of problem  Well, it depends on the technology actually as you saw if you use a keeper you can connect to multiple hosts  So you don't need a load balancer just but every of the node in this on the other hand in  Console and each cd you have to specify one of those on one of the nodes  So maybe you can implement some kind of stuff on your application to handle this  Like having a dq or something like this in python and try again in each  Exception if you it's it's raises an exception you can try and connect to the other host etc etc  Yeah  I think for the recording sorry a  Question about registration procedure. Yeah, why don't you want to use external tool to do this it can be  Implemented in  configuration management chief puppet salt  And in this case you will have possibility to register  Sort by the services like MongoDB and so on automatically  So  That's question why not do this as external service for your application?  well  Hmm, I think  To me chef and stuff like that are good for provisioning or  configuration really configuration  Applying configuration to servers. I don't see service discovery like this  to me is I  relate to your point with MongoDB and and and  Demand stuff like this  You have external programs that do it for you  I'm not sure that  For instance chef etc can have have checks running on  So if you make with with ETCD it may become difficult to do  There are a lot of third parties libraries doing it for ETCD for example because it has a wide audience and  For containers stuff like this  They they use specific third party tools, but not provisioning tools  Yeah, we are using register container that register  container that  automatically registers any container that is running on  Docker host and it's it's very  Good idea. I think it's yeah, it works well and it's if something happens with container it will be there just automatically  Yeah, but it has to be registered somewhere anyway  Yeah, we are running local agent on each host machine local consulate agent and each  service knows that it can find  agent on local host and  Engine only agent knows where there is a console cluster located  It's can be implemented in very easy way. Yeah, but you don't have  Central configuration place or you you do it also in them  We are using salt to to install everything, but actually a service discovery is  Implemented using special containers. Okay  No other question  Well, thank you. I
Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_0_95.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_96_1343.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_1344_2231.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_2232_3527.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_3528_5219.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_5220_10643.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_10644_13163.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_13164_14771.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_14772_15347.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_15348_15827.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_15828_19607.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_19608_20159.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_20160_21203.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_21204_26351.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_26352_27239.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_27240_27383.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_27384_27467.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_27468_29195.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_29196_31631.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_31632_31799.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_31800_32231.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_32232_34319.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_34320_34391.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_34392_34907.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_34908_35075.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_35076_35567.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_35568_36059.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_36060_36251.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_36252_37043.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_37044_37127.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_37128_38111.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_38112_39755.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_39756_39803.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_39804_40259.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_40260_40655.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_40656_41519.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41520_41567.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41568_41711.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41712_41819.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41820_41915.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41916_41975.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_41976_43379.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_43380_43451.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_43452_50459.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_50460_50543.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_50544_50651.png Alexys_Jacob_-_Using_Service_Discovery_to_build_dynamic_python_applications_50652_50926.png