Building Cloud Native Applications
Learn how building an application in the cloud is different than building other everyday applications.
Join the DZone community and get the full member experience.Join For Free
the nature of my job forces me to build quick simple sample applications that are easy to understand and demonstrate a single concept. after all i am trying to enable developers, and making something overly complex generally turns developers off when they are trying to learn something new. however i often hear questions about how to build real world production grade applications that run in the cloud. this is something that is very hard to demonstrate simply because, lets face it, no production quality application has ever been considered simple to understand. however, i do think it is an important topic to address because if you are serious about building an application in the cloud you should understand how cloud applications are different from your everyday app that everyone is familiar with building.
in my opinion, the cloud was originally marketed to developers as “the same thing you have today but a vendor is taking care of the infrastructure”. in some ways this is true, take any cloud vendor that allows you to request a vm from them. it feels just like the vm you had running in your own data center for the most part. the only difference is that its not in your data center. the fact that it is not running in your datacenter is exactly the reason why cloud applications need to be architected differently. the lack of absolute control and predicability of the cloud is what makes it necessary to think differently when running applications in the cloud. everything from the hardware to the networking is all someone elses responsibility, and you can’t even get that person on the phone if you think something is wrong. on top of that, if you are serving millions upon millions of people every day (i.e. netflix, amazon, google) by the time your realize something is wrong it is too late, you have already lost a huge chunk of money.
so at the e nd of the day if you are serious about building and running an application in the cloud you need to first understand that you should not be building a cloud application like it is running in your own data center. you need to build it with every intention of it running in a very volatile place where much of what lies underneath your application is completely our of your control. a term has recently emerged for applications that have built to be run in the cloud, we refer to them as “cloud native applications”. so what makes an application a cloud native application? in matt stine’s book “ migrating to cloud-native application architectures ” he describes cloud native applications as having the following characteristics:
- is a 12-factor application
- follows a microservices architecture
- uses self-service agile infrastructure – aka a platform-as-a-service
- uses api-based collaboration
- is antifragile
lets look at each of these in more detail.
when heroku was first introduced it was such a new concept that the engineers there came up with a set of guidelines for developers trying to use the platform. there ended up being 12 common practices that all successful applications deployed to heroku had in common, they called these applications 12-factor applications. all of the applications had the following in common:
- once codebase tracked in revision control, multiple deploys
- explicitly declare and isolate dependencies
- store config in the environment
- treat backing resources as attaches resources
- sticky separate build and run stages
- execute the app as one or more stateless resources
- export services via port binding
- scale out via the process model
- maximize robustness with fast startup and graceful shutdown
- keep development, staging, and production as similar as possible
- treat logs as events streams
- run admin/management tasks as one-off processes
i won’t describe the details behind each one of these guidelines, instead i will let you read more about them on 12factor.net .
if you have not heard of the term microservices yet than you have not been looking into building cloud applications for too long you cannot read a blog post or attend a conference on cloud today without hearing something about it. what is it? i think martin fowler and james lewis describe it best:
in short, the microservice architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an http resource api.
in essence we are all used to building large monolithic applications. these applications typically package everything into a single artifact that needs to be built, tested, and deployed to an application server and typically has a 3 tier architecture . so why do monolithic apps not work in the cloud? one reason is they are slow. building them is slow, testing them is slow, deploying them is slow. with cloud native applications we want as much speed as possible. they are also very fragile, if one component in the monolith crashes everything goes down with it. this is not acceptable in the cloud. they are also not easy to scale. if i need to scale a single component of my application i end up scaling the entire monolith. this requires me to consume more infrastructure and therefore pay more money to my cloud provider.
when you build an application using microservices all of these issues go away and your application is much more suited for the cloud. much of what it means to build a cloud native application builds off of using microservices including the rest of the characteristics mentioned in this blog post. i will look at microservices in detail in future blog posts.
self-service agile infrastructure
another term for self-service agile infrastructure is platform-as-a-service. in essence when deploying cloud native applications you do not want to go through the process of requesting a vm, configuring that vm, securing that vm, installing dependencies, deploying your application, configuring your application, and setting up tools to monitor your application, you want my platform to do that for you. remember, if our cloud native application is using microservices it can potentially have 100s of services that need to be deployed in order for the application to work. going through the above process for each microservice is not going to scale, no matter how many people work on the team.
contrast the above process to one where you use a platform-as-a-service. all you need to do is hand the platform your application code and it takes care of the rest. of course this can also be automated via tools like jenkins and other build and deploy tools (perhaps your platform has these tools built in, i.e. ibm bluemix and devops services).
the self-service agile infrastructure should also be responsible for providing your application with the backing services is needs to run. things like databases, message queues, and caching services should be able to requested on demand and provisioned rapidly when an application is deployed.
api based collaboration
when you are following the microservice design pattern you are going to need a new way for the components in your application to communicate. you cannot rely on just making method calls between the components of your application anymore. having versioned rest apis is the most common way for your services to communicate in cloud native applications. these may not be public apis you let external consumers use, but you should consider them like they are. other microservices will rely on these apis and changes to them can drastically effect how the other microservices work so thinking carefully about your apis is very important in a cloud native application.
using rest apis will also be helpful in supporting various types of clients. the most robust cloud native applications today support desktops, browsers, phones, tablets, watches, tvs, cars, entertainment systems, game consoles, and may other types of clients. the protocol that works best for all these types of devices is rest.
with that said, in certain types of situations other protocols may be preferred. this is fine, if it makes sense for your use case, but it typically is for internal communication between services and not external communication with clients.
todays cloud native applications are expected to have 0 down time. if facebook goes down it is on the national news. will your application be subject to the same level of scrutiny or publicity? probably not, but i guarantee your application is just as important to your customer as facebook is to the entire world so you can be sure you will hear for them if your application is not available. the good news is that by following a microservices architecture you are already making sure your application is more robust. a crash in one component should still leave the majority of your application available to your users. if you take advantage of different data centers and regions from your cloud provider you have enough redundancy to withstand an entire outage of your application in one region without anyone even noticing! there are other tools and patterns you can implement in your application that helps your application be even more robust and i will talk about some of these in future posts.
Published at DZone with permission of Ryan Baxter, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.