# Application layer

![](https://2407442552-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lpv9LvHzpublmUWisvz%2Fsync%2Facc20c3f93c98e45931f7cde29b3059505c363bb.png?generation=1591683425143318\&alt=media)

Separating out the web layer from the **application layer** (also known as **platform layer**) allows you to **scale and configure both layers independently**. Adding a new API results in adding application servers without necessarily adding additional web servers. The single responsibility principle advocates for small and autonomous services that work together. Small teams with small services can plan more aggressively for rapid growth.

> application layer 这个概念的提出是为了把一系列的东西打包从 web server 当中分离出去，这样就能更好地 scale system 了

Workers in the application layer also help enable asynchronism.

## Microservices

Related to this discussion are [microservices](https://en.wikipedia.org/wiki/Microservices), which can be described as a suite of **independently deployable**, **small**, **modular** services. Each service runs a unique process and communicates through a well-defined, lightweight mechanism to serve a business goal.

Pinterest, for example, could have the following microservices: user profile, follower, feed, search, photo upload, etc.

## Service Discovery

Systems such as [Consul](https://www.consul.io/docs), [Etcd](https://etcd.io/), and [Zookeeper](https://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper) can help services find each other by keeping track of registered names, addresses, and ports. [Health checks](https://learn.hashicorp.com/consul/getting-started/services) help verify service integrity and are often done using an [HTTP](https://github.com/donnemartin/system-design-primer#hypertext-transfer-protocol-http) endpoint. Both Consul and Etcd have a built in [key-value store](https://github.com/donnemartin/system-design-primer#key-value-store) that can be useful for storing config values and other shared data.

## Disadvantage(s): application layer

* Adding an application layer with loosely coupled services requires a different approach from an architectural, operations, and process viewpoint (vs a monolithic system).
* Microservices can add complexity in terms of deployments and operations.

## More read

* [Intro to architecting systems for scale](https://lethain.com/introduction-to-architecting-systems-for-scale/)
* [Crack the system design interview](https://tianpan.co/notes/2016-02-13-crack-the-system-design-interview)
* [Service oriented architecture](https://en.wikipedia.org/wiki/Service-oriented_architecture)
* [Introduction to Zookeeper](https://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper)
* [Here's what you need to know about building microservices](https://cloudncode.blog/2016/07/22/msa-getting-started/)
