<p>I think you're taking the problem on the wrong side, you may start a whole new infrastructure aside and then switch loadbalancers from blue to green, loosing sessions, breaking ongoing transactions etc.</p>

<p>The proper way to achieve what you're doing is coding differently, when A relasease a breaking API ni version n, a should be able to continue to answer call to api in version n-1. the usual method is to have the version in the uri or an header, for exemple:</p>

<p><code>&lt;a-host&gt;/api/1/getCustomers</code> and <code>&lt;a-host&gt;/api/2/getCustomerList</code> (for exemple if n is 2). With that, you can do a rolling update of B, with backends still using api v1 and new ones using api v2.</p>

CC BY-SA 3.0
2018-04-27T13:45:15.087Z
2018-04-27T13:45:15.087Z
Tensibai
<p>I will make the following assumptions:</p>

<ul>
<li>Service B communicates with Service A using any Application layer protocol (such as HTTP)</li>
<li>Service B is the only consumer of Service A</li>
<li>Users only interacts with Service B</li>
</ul>

<p><strong>Solution with down time</strong></p>

<p>When upgrading Service A with breaking changes, move these changes to another "version".</p>

<p>The goal is for you to proactively create a new interface version (i.e. API version) that will implement the breaking changes. In some situation, this might require heavy refactoring. In other (depending if your code base was properly layered), not. Then you can start implementing "contract" tests between Service A and B to make sure A doesn't break the contract with B.</p>

<p>The problem here is that when deploying this solution, for a short while you will not have access to neither API.</p>

<p><strong>Solution without down time</strong></p>

<p>Make the same change as the solution above, but also consider a deployment strategy where Service A.1 is always up while we introduce Service A.2. When no requests to A.1 is incoming, it may go down to leave only A.2 alive to serve all the requests. This is the blue-green deployment strategy.</p>

<p>This is more a cherry on the top if your overall solution requires minimal downtime deployment.</p>

CC BY-SA 3.0
2018-04-28T14:55:50.987Z
2018-04-28T14:55:50.987Z
gmolaire
<p>I have two different services. Let's say Service A and Service B. Service B is dependent on Service A. Both code bases are hosted in separate repo in Bitbucket and code bases are maintained by different teams. Service A has three backend servers and Service B has seven backend servers. I use Jenkins as a CI for code deployment. So, whenever we merge the code in master branch, Jenkins start the deployment. The process is same for Service A and Service B but they have two different Jenkins server.</p>

<p>Now, problem is that if Service A team deploy something in production independently with major changes in code base. Then whole application will break. Because Service B is not ready yet to compatible with the code changes of Service A. Let's say, parameters of a function has been changed where Service B is expecting a different parameter.</p>

<p>I am looking for a solution, where Service A code merge in master gonna happen only it is time for deployment of Service B. So, every deployment of Service B, it first deploys the code of Service A and then follows with Service B. This whole deployment will take a lot of time. Main application should not be down by this time (because once Service A is deployed then user has to wait for Service B deployment, otherwise they will face errors). </p>

<p>So, I am thinking if it's possible where new deployment will happen in a separate instance When deployment is completed in that instance then it will replace the previous instance. So, code will be updated in main production without any down time or error. </p>

<p>What is the recommended way to achieve this ? Can I do something with <code>Ansible</code> in this case ?</p>

<jenkins><ansible><continuous-integration><linux><bitbucket>
Deploy two independently hosted services in production at once without any downtime
Cyberzinga
# Deploy two independently hosted services in production at once without any downtime

(Asked by: username_0 on 2018-04-27)

I have two different services. Let's say Service A and Service B. Service B is dependent on Service A. Both code bases are hosted in separate repo in Bitbucket and code bases are maintained by different teams. Service A has three backend servers and Service B has seven backend servers. I use Jenkins as a CI for code deployment. So, whenever we merge the code in master branch, Jenkins start the deployment. The process is same for Service A and Service B but they have two different Jenkins server.

Now, problem is that if Service A team deploy something in production independently with major changes in code base. Then whole application will break. Because Service B is not ready yet to compatible with the code changes of Service A. Let's say, parameters of a function has been changed where Service B is expecting a different parameter.

I am looking for a solution, where Service A code merge in master gonna happen only it is time for deployment of Service B. So, every deployment of Service B, it first deploys the code of Service A and then follows with Service B. This whole deployment will take a lot of time. Main application should not be down by this time (because once Service A is deployed then user has to wait for Service B deployment, otherwise they will face errors).

So, I am thinking if it's possible where new deployment will happen in a separate instance When deployment is completed in that instance then it will replace the previous instance. So, code will be updated in main production without any down time or error.

What is the recommended way to achieve this ? Can I do something with `Ansible` in this case ?

**Tags:** jenkins, ansible, continuous-integration, linux, bitbucket


---

## 2 answers

### Answer by username_1 on 2018-04-27. Score: 2

I think you're taking the problem on the wrong side, you may start a whole new infrastructure aside and then switch loadbalancers from blue to green, loosing sessions, breaking ongoing transactions etc.

The proper way to achieve what you're doing is coding differently, when A relasease a breaking API ni version n, a should be able to continue to answer call to api in version n-1. the usual method is to have the version in the uri or an header, for exemple:

`/api/1/getCustomers` and `/api/2/getCustomerList` (for exemple if n is 2). With that, you can do a rolling update of B, with backends still using api v1 and new ones using api v2.


---

### Answer by username_2 on 2018-04-28. Score: 0

I will make the following assumptions:

* Service B communicates with Service A using any Application layer protocol (such as HTTP)
* Service B is the only consumer of Service A
* Users only interacts with Service B

**Solution with down time**

When upgrading Service A with breaking changes, move these changes to another "version".

The goal is for you to proactively create a new interface version (i.e. API version) that will implement the breaking changes. In some situation, this might require heavy refactoring. In other (depending if your code base was properly layered), not. Then you can start implementing "contract" tests between Service A and B to make sure A doesn't break the contract with B.

The problem here is that when deploying this solution, for a short while you will not have access to neither API.

**Solution without down time**

Make the same change as the solution above, but also consider a deployment strategy where Service A.1 is always up while we introduce Service A.2. When no requests to A.1 is incoming, it may go down to leave only A.2 alive to serve all the requests. This is the blue-green deployment strategy.

This is more a cherry on the top if your overall solution requires minimal downtime deployment.


---

