Managing Microservices with Neo4j
Here's a look at microservices management, specifically Neo4j microservice management. Plus, a special appearance by MacGyver (sort of).
Join the DZone community and get the full member experience.Join For Free
rob shoening: lending club is the world’s largest credit marketplace and we’re shaking up the financial services industry. we’re also trying to shake up the financial technology space and that’s what we’re going to talk about here.
we started this as a hobby , and now it’s running our infrastructure of a publicly traded company. it’s a good story.
microservices: everyone is doing it
we’ve talked to nobody who’s not doing microservices.
lending club’s microservices exploded from five microservices (in 2013) to 139 microservices in 2015.
we had five production microservices in 2013, and right now in 2015, the last count i had was 139 microservices (out of neo4j , of course).
earlier today, someone asked me about my microservices transition. i told him we had moved from five to 139, and he responded, “i’m glad to hear that, because a lot of people get stuck along the way.”
this is what everybody thinks of when moving to microservices:
the container analogy is nice and neat, but this can be what happens:
i don’t think it’s unusual to have these issues either. one of the most common questions is “is it the load balancer?” that question will be our common theme today since we’re doing a lot of load balancer management.
so how do we get from five to 139 microservices, continuously deliver agile financial technology and still meet all audit and compliance requirements? that’s what we’re going to talk about.
it’s not a joke. you probably remember macgyver from the ’80s. (ashley doesn’t).
what is it? it’s all the stuff that jenkins can’t do. jenkins is great at a whole bunch of things, and it’s fantastic at orchestrating continuous integration and continuous delivery. jenkins is a swiss army knife, but there’s certain things it just doesn’t do at all:
- it can’t do real-time api access.
- there’s no database to speak of.
- anything interactive in managing state of infrastructure.
so we put macgyver together based on neo4j to fill that deficiency. with that, i’m going to hand it off to ashley for the fun stuff.
ashley sun: macgyver is hooked into a lot of different services at lending club.
here are a few:
- and plenty more
there are a lot of things it’s hooked into, and it’s constantly talking to all these different services. from the load balancer, we’ll have service groups; from aws, we’ll have ec2 instances; from the firewall rules or our san storage, we’ll have any number of arrays and volumes.
we needed a good way to keep track of these things. while we could use an operational data store, real-time access is costly.
with operational data stores, if you wait to get the data until you actually need it, then it’s too late, and you find yourself looking one by one through each of these silos. you also limit yourself to very simple queries, and you’re limited to a very small amount of data so it’s not scalable.
instead, we use neo4j. neo4j has all of the characteristics of a database that we need:
- really fast queries
- really great join and traversal capabilities
- really easy to use
- really flexible
- really scalable
- really great ad hoc queries through cypher
so, how do we use neo4j at lending club?
app check-in and service discovery
we have three use cases: first, we use it for app check-in and service discovery.
as rob mentioned, just a couple years ago, we had five microservices and now we have 139. (actually i think it’s closer to 150 now.) when we have over 1,000 servers, it’s hard to keep track of what’s out there, and what’s going on, so we configured all of our servers to phone home to macgyver every minute, and we saved all those app instances into neo4j.
above, you’ll see the app instances, and every minute they phone home to macgyver with information about their app id, any revisions, and what environment they’re running in. we save all that information into neo4j.
this seems super simple but just by implementing this use case, we immediately started to reap a lot of benefits. we had a real-time database with deployed infrastructure, so every minute the info is kept up to date.
also, when we add new services they automatically report in to macgyver. they report in, they get saved to neo4j, and we start monitoring them right away so it’s super easy to scale.
just from this improvement we were able to ask queries like, “show me all the instances of app x in environment y.”
this query was hard to look up before. we had to actually go into vcenter and look up all our different vms, and now we can just use a simple query showing all the app instances with a given app id and given environment.
immediately we were able to get a lot more visibility into what app instances we had out there.
then, we decided to take macgyver and neo4j a step further with deployment and release automation.
deployment and release automation
in the past, our deployment and release process was highly manual and very tedious.
we would use excel spreadsheets or even handwritten notes to cross things off of our list. it was really hard to answer questions like:
- what pool should i deploy to?
- is the most recent revision “live” right now?
- are live pool revisions in sync in different environments?
answering all of these questions would require a manual look-up by devops team. we didn’t have a lot of visibility into our services.
our solution to that problem was to take our app instances that we saved into neo4j, combine it with some info from our load balancer, and then manipulate that data into neo4j so we could expose information about our live and dark pools. this ultimately enabled us to automate our deployments in a release.
at lending club, we use blue-green deployments. in a blue-green deployment, we have a live pool and a dark pool at any given time, so half the servers are live and half of them are dark within a service group.
the live pool takes all the traffic, while the dark pool is inactive. during a deployment, we deploy new code to the dark pool, and then qa and release run testing on it.
once they say okay, the dark pool is good to go, we change the state on the dark pool so that it becomes active with a high priority, and we also lower the priority of the pool that’s on the left.
after that switch, all new connections are sent to the newly live pool on the right and we wait for all of the old connections on the previously live pool to drain out on the left. once those old connections reach zero, we cut that pool over.
essentially, we’ve just done a pool flip. now the pool on the right is live, and the pool on the left is dark.
although we had this concept of pools, the load balancer could associate servers with each service group, but it couldn’t tell which servers were in what pool.
also, the app instances that were being reported to macgyver knew their revision and app id, but they didn’t know their state. they didn’t know if they were live or dark.
to solve that problem, we were able to use neo4j to map these servers into pools and automate our deployments.
this involves what we just talked about where app instances are saved into neo4j. we took the info from the app instances – such as app id, revisions, environment – and we combined that information. we then polled our load balancer for information on servers – such as state; whether it’s active, inactive, draining; how many connections does that server have – and we combine that with our app instance nodes, and we were able to create virtual server nodes.
by collecting virtual servers and aggregating them according to their app id and their state, we were able to create pools, which is where it gets a little more interesting.
these (above) are application pools in neo4j, and you’ll see the purple dot is a pool. each pool contains many servers and each of those servers has a one-to-one mapping to our app instances.
because it’s pulling info from its virtual servers, each pool knows whether it’s live, dark or draining. each service has a live pool and a dark pool; pool a and pool b. so by mapping the pools into a virtual service, for every service we have a green dot and there are two pools (below).
as before, within a pool there are many servers which are then mapped to app instances.
because of this data model, we gained a lot of visibility into apps that we didn’t have before, and questions that had once been difficult to answer became easy with neo4j.
for example, let’s answer the question, “what pool should i deploy to?”
usually, we would have to bounce into the a10 gui and look up which servers were active or inactive, but that’s all solved with a simple cypher query (below).
right away, it’s easy to tell what pool we want to deploy to.
another example: “are live pool revisions in sync in different environments?”
this is important because, say, our main load balancer fails over to our backup load balancer. in this case, we want to make sure there’s not old code running and that it’s the same revision.
this also becomes a simple cypher query (below) which before would have required manual look-up.
here’s an important one: “do multiple revisions exist within a single pool?”
we don’t want old code and new code running at the same time, and so we just query: “show me all the servers within a pool” and if there’s more than one revision within a pool then we know that’s a problem.
if you think about the knight capital meltdown in 2012, they lost $440 million because they had old and new code deployed at the same time.
rob: that was the end of that company, i believe, or they got sold off for nothing.
ashley: yeah, this happened in like 45 minutes. so if you do the math, it’s $163,000 that they were losing per second, which is crazy. they should have been using neo4j.
rob: it’s an easy mistake to make, so if it were to happen, we get paged.
ashley: a lot of these queries we periodically run throughout the day, and they’ll page us. they’ll tell us if something is wrong.
so, a high-level overview of what we just covered: the app instances report in to macgyver, they get saved to neo4j, we take some info from the load balancer and combine that with our app instance info and from that we are able to create virtual servers. from there, we group those servers into pools and then we connect those pools into virtual services.
the reason we were able to do all this for deployment and release automation was because of these pools that we were able to create with neo4j.
because neo4j is so good at mapping relationships , it was really perfect for this use case. not only can we monitor all the virtual services, but at the same time, we can also send commands to the load balancer and this is how we’re able to automate our deployments.
at any time you can say, “i want to deploy this revision of this app into this environment.” macgyver can then respond, “this pool is dark. we’re going to deploy to this pool.”
so you can deploy macgyver, and then you can start a drain in macgyver. then, because macgyver knows the number of connections to all of its servers, it can automatically just cut the pool over.
the last use case: infrastructure mapping.
similar to the problem with our services, we didn’t have a lot of visibility into what pools were live, what pools were dark, what servers were in a virtual service or even what app instances were out there. this problem extended to our entire infrastructure.
once we got started with neo4j , we played around with virtual servers and services and realized, “hey, we can map out our entire infrastructure with this.”
so here you’ll see what we just talked about:
every virtual service contains two pools, which contain a number of virtual servers, which maps to an app instance. exposing this data allowed us to ask, “are any servers in the live pool degraded?”
we don’t want an unhealthy server in our live pool, so basically the state and the priority is what determines if the server is live and active, if it’s healthy. if those conditions aren’t met, then it returns that server and we get a ping about it.
from there, we decided to add stuff from vcenter, so all the app instances map to compute instances which are hosted by compute hosts and so we added a bunch more nodes from vcenter into neo4j (below).
we were able to extend this so now we can ask the question, “do we have a single point of failure among our services?”
if at any given time within a pool all those servers are hosted on one host in vcenter, if that host is to go down, then we definitely have a problem. because we are mapping this in neo4j, we are able to expose this data in a way that we weren’t able to before.
this query is kind of blurry, but it shows the traversal pretty well from pool to virtual server to app instance to compute instance to compute host.
rob: i love this because vcenter has a habit with vmotion of deciding to move things around. if you don’t have affinity set up in vcenter, it’s real easy to set yourself up for these single points of failure.
before neo4j, we were constantly scanning the infrastructure, and i’d be asking staff, “is it okay? can you look again?”
but we want the infrastructure to tell us . we want to be reacting to problems, not having to go constantly look.
ashley: this problem is also really hard if you’re just looking in vcenter at a host. it’s hard to know if there is a single point of failure.
so really, we weren’t just taking data but making sense of it within neo4j and exposing it in a way that was useful to us.
so to continue with our infrastructure diagram:
the nimbles at the bottom are our storage arrays and our storage volumes. if we wanted, we can traverse this graph all the way from a virtual service to, for example, a storage array or a storage volume.
now we want to ask a question: “if this storage volume goes down, what services are going to be impacted?”
again, it’s a really simple query, it runs really quickly and it tells us things we never had visibility into before.
other use cases
i think the cool thing here, as rob was saying, is that it started out where we were using neo4j as a hobby. we thought, “oh, it would be cool if we put our app instances into neo4j.” from there, we were like, “oh, app instances, we can wrap those pretty easily into virtual services.”
then, because that information was there, we were able to automate our deployments and from there we kept building and building on our dataset that we already had. that is one of the things i think is cool about neo4j: that you can develop incrementally.
when we first started, we didn’t know we were going to end up with this full deployment. and we’re still progressing.
we’re adding firewall rules; we could add databases; as we move into amazon, we can get ec2 instances and security groups. it’s pretty cool. it’s easy to build on your dataset, and make it more complex.
also, our information security group has recently taken an interest in macgyver for service onboarding. we now have a service registration in macgyver, so when we get new services, we can register with macgyver.
we can determine if a service is allowed to talk to another one, and we have a graph of relationships of services that depend on one another and talk to each other. we also use that graph for rezoning. is this server in the correct security zone?
using neo4j and microservices for greater agility
rob: we want to keep this agile culture going in the company, and we don’t want to have meetings and change review boards and all that kind of stuff that nobody really likes.
the information security use cases are a great one for the continuation of devops. and when we’re thinking about how we are going to move from five services to 139 to 400 – at the same time as the company is getting bigger – we can’t have meetings and change review boards to get there.
our information security group is on board with this because they want to hook into it, and they want to react to chaining workflows around new services created by developers.
then, they want to dig into it, asking, “now maybe i need to start running app scans on the new service. maybe i need to have a conversation with that scrum team to understand what it is. maybe i’m going to ask them to provide attributes about it so that we know how to do data classification.”
the opportunities for continuing this devops mindset with neo4j, it’s limitless.
we’re really excited, particularly with moving into aws and the api control plane that has such a rich variety of information, even though it’s kind of hard to query. as we’ve started doing that automation, it’s slow – something that will take 15 seconds to make 20 different queries out to aws – but we want it to come back in a snap so we can have fast, responsive apis that allow us to deliver the services that we want.
ashley: in the end, everything is awesome when you use neo4j.
we have a lot of individual microservices (or “lego blocks”) and we can switch them out or move them around. as rob was saying, sometimes things can get messy, but using neo4j to manage it has made it a lot easier , and we’ll continue to use neo4j.
inspired by ashley and rob’s talk? register for graphconnect europe on april 26, 2016 at for more industry-leading presentations and workshops on the evolving world of graph database technology.
register for graphconnect europe
by ashley sun & rob schoening , devops team at lending club | december 30, 2015
editor’s note: last october at
graphconnect san francisco
, ashley sun and rob schoening – from the devops team at lending club – delivered this in-depth presentation on their macgyver platform for managing microservices with neo4j.
for more videos from graphconnect sf and to register for graphconnect europe, check out graphconnect.com .
Published at DZone with permission of Rob Schoening. See the original article here.
Opinions expressed by DZone contributors are their own.
Introduction to Domain-Driven Design
Constructing Real-Time Analytics: Fundamental Components and Architectural Framework — Part 2
Mastering Go-Templates in Ansible With Jinja2
Event-Driven Architecture Using Serverless Technologies