poriting to noat.cards
parent
6984b4e956
commit
f4af06bdff
|
@ -0,0 +1,42 @@
|
||||||
|
+++
|
||||||
|
noatcards = True
|
||||||
|
isdraft = False
|
||||||
|
+++
|
||||||
|
|
||||||
|
Application layer
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
### Application layer - Introduction
|
||||||
|
|
||||||
|
[![](https://camo.githubusercontent.com/feeb549c5b6e94f65c613635f7166dc26e0c7de7/687474703a2f2f692e696d6775722e636f6d2f7942355359776d2e706e67) ](https://camo.githubusercontent.com/feeb549c5b6e94f65c613635f7166dc26e0c7de7/687474703a2f2f692e696d6775722e636f6d2f7942355359776d2e706e67)
|
||||||
|
|
||||||
|
_[Source: Intro to architecting systems for scale](http://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer) _
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
Workers in the application layer also help enable [asynchronism](https://github.com/donnemartin/system-design-primer#asynchronism) .
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#microservices) 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-definied, lightweight mechanism to serve a business goal. [1](https://smartbear.com/learn/api-design/what-are-microservices)
|
||||||
|
|
||||||
|
Pinterest, for example, could have the following microservices: user profile, follower, feed, search, photo upload, etc.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#service-discovery) Service Discovery
|
||||||
|
|
||||||
|
Systems such as [Zookeeper](http://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper) can help services find each other by keeping track of registered names, addresses, ports, etc.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-application-layer) 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.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#sources-and-further-reading-9) Source(s) and further reading
|
||||||
|
|
||||||
|
* [Intro to architecting systems for scale](http://lethain.com/introduction-to-architecting-systems-for-scale)
|
||||||
|
* [Crack the system design interview](http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/)
|
||||||
|
* [Service oriented architecture](https://en.wikipedia.org/wiki/Service-oriented_architecture)
|
||||||
|
* [Introduction to Zookeeper](http://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper)
|
||||||
|
* [Here's what you need to know about building microservices](https://cloudncode.wordpress.com/2016/07/22/msa-getting-started/)
|
|
@ -0,0 +1,50 @@
|
||||||
|
+++
|
||||||
|
noatcards = True
|
||||||
|
isdraft = False
|
||||||
|
+++
|
||||||
|
|
||||||
|
# Asynchronism
|
||||||
|
|
||||||
|
[![](https://camo.githubusercontent.com/c01ec137453216bbc188e3a8f16da39ec9131234/687474703a2f2f692e696d6775722e636f6d2f353447597353782e706e67) ](https://camo.githubusercontent.com/c01ec137453216bbc188e3a8f16da39ec9131234/687474703a2f2f692e696d6775722e636f6d2f353447597353782e706e67)
|
||||||
|
_[Source: Intro to architecting systems for scale](http://lethain.com/introduction-to-architecting-systems-for-scale/#platform_layer) _
|
||||||
|
|
||||||
|
Asynchronous workflows help reduce request times for expensive operations that would otherwise be performed in-line. They can also help by doing time-consuming work in advance, such as periodic aggregation of data.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#message-queues) Message queues
|
||||||
|
|
||||||
|
Message queues receive, hold, and deliver messages. If an operation is too slow to perform inline, you can use a message queue with the following workflow:
|
||||||
|
|
||||||
|
* An application publishes a job to the queue, then notifies the user of job status
|
||||||
|
* A worker picks up the job from the queue, processes it, then signals the job is complete
|
||||||
|
|
||||||
|
The user is not blocked and the job is processed in the background. During this time, the client might optionally do a small amount of processing to make it seem like the task has completed. For example, if posting a tweet, the tweet could be instantly posted to your timeline, but it could take some time before your tweet is actually delivered to all of your followers.
|
||||||
|
|
||||||
|
Redis is useful as a simple message broker but messages can be lost.
|
||||||
|
|
||||||
|
RabbitMQ is popular but requires you to adapt to the 'AMQP' protocol and manage your own nodes.
|
||||||
|
|
||||||
|
Amazon SQS, is hosted but can have high latency and has the possibility of messages being delivered twice.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#task-queues) Task queues
|
||||||
|
|
||||||
|
Tasks queues receive tasks and their related data, runs them, then delivers their results. They can support scheduling and can be used to run computationally-intensive jobs in the background.
|
||||||
|
|
||||||
|
Celery has support for scheduling and primarily has python support.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#back-pressure) Back pressure
|
||||||
|
|
||||||
|
If queues start to grow significantly, the queue size can become larger than memory, resulting in cache misses, disk reads, and even slower performance. [Back pressure](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) can help by limiting the queue size, thereby maintaining a high throughput rate and good response times for jobs already in the queue. Once the queue fills up, clients get a server busy or HTTP 503 status code to try again later. Clients can retry the request at a later time, perhaps with [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) .
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-asynchronism) Disadvantage(s) : asynchronism
|
||||||
|
|
||||||
|
* Use cases such as inexpensive calculations and realtime workflows might be better suited for synchronous operations, as introducing queues can add delays and complexity.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#sources-and-further-reading-11) Source(s) and further reading
|
||||||
|
|
||||||
|
* [It's all a numbers game](https://www.youtube.com/watch?v=1KRYH75wgy4)
|
||||||
|
* [Applying back pressure when overloaded](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html)
|
||||||
|
* [Little's law](https://en.wikipedia.org/wiki/Little%27s_law)
|
||||||
|
* [What is the difference between a message queue and a task queue?](https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function)
|
||||||
|
|
||||||
|
[](https://github.com/donnemartin/system-design-primer#communication)
|
||||||
|
---------------------------------------------------------------------
|
|
@ -0,0 +1,69 @@
|
||||||
|
+++
|
||||||
|
noatcards = True
|
||||||
|
isdraft = False
|
||||||
|
+++
|
||||||
|
|
||||||
|
# Availability patterns
|
||||||
|
|
||||||
|
There are two main patterns to support high availability:fail-over and replication.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#active-passive) Active-passive (Fail-Over)
|
||||||
|
|
||||||
|
With active-passive fail-over, heartbeats are sent between the active and the passive server on standby. If the heartbeat is interrupted, the passive server takes over the active's IP address and resumes service.
|
||||||
|
|
||||||
|
The length of downtime is determined by whether the passive server is already running in 'hot' standy or whether it needs to start up from 'cold' standby. Only the active server handles traffic.
|
||||||
|
|
||||||
|
Active-passive failover can also be referred to as master-slave failover.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#active-active) Active-active (Fail-Over)
|
||||||
|
|
||||||
|
In active-active, both servers are managing traffic, spreading the load between them.
|
||||||
|
|
||||||
|
If the servers are public-facing, the DNS would need to know about the public IPs of both servers. If the servers are internal-facing, application logic would need to know about both servers.
|
||||||
|
|
||||||
|
Active-active failover can also be referred to as master-master failover.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-failover) Disadvantage(s) : failover
|
||||||
|
|
||||||
|
* Fail-over adds more hardware and additional complexity.
|
||||||
|
* There is a potential for loss of data if the active system fails before any newly written data can be replicated to the passive.
|
||||||
|
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#master-slave-and-master-master) Master-slave replication
|
||||||
|
|
||||||
|
The master serves reads and writes, replicating writes to one or more slaves, which serve only reads. Slaves can also replicate to additional slaves in a tree-like fashion. If the master goes offline, the system can continue to operate in read-only mode until a slave is promoted to a master or a new master is provisioned.
|
||||||
|
|
||||||
|
[![](https://camo.githubusercontent.com/6a097809b9690236258747d969b1d3e0d93bb8ca/687474703a2f2f692e696d6775722e636f6d2f4339696f47746e2e706e67) ](https://camo.githubusercontent.com/6a097809b9690236258747d969b1d3e0d93bb8ca/687474703a2f2f692e696d6775722e636f6d2f4339696f47746e2e706e67)
|
||||||
|
_[Source: Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) _
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-master-slave-replication) Disadvantage(s) : master-slave replication
|
||||||
|
|
||||||
|
* Additional logic is needed to promote a slave to a master.
|
||||||
|
* See [Disadvantage(s) : replication](https://github.com/donnemartin/system-design-primer#disadvantages-replication) for points related to both master-slave and master-master.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#master-master-replication) Master-master replication
|
||||||
|
|
||||||
|
Both masters serve reads and writes and coordinate with each other on writes. If either master goes down, the system can continue to operate with both reads and writes.
|
||||||
|
|
||||||
|
[![](https://camo.githubusercontent.com/5862604b102ee97d85f86f89edda44bde85a5b7f/687474703a2f2f692e696d6775722e636f6d2f6b7241484c47672e706e67) ](https://camo.githubusercontent.com/5862604b102ee97d85f86f89edda44bde85a5b7f/687474703a2f2f692e696d6775722e636f6d2f6b7241484c47672e706e67)
|
||||||
|
_[Source: Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) _
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-master-master-replication) Disadvantage(s) : master-master replication
|
||||||
|
|
||||||
|
* You'll need a load balancer or you'll need to make changes to your application logic to determine where to write.
|
||||||
|
* Most master-master systems are either loosely consistent (violating ACID) or have increased write latency due to synchronization.
|
||||||
|
* Conflict resolution comes more into play as more write nodes are added and as latency increases.
|
||||||
|
* See [Disadvantage(s) : replication](https://github.com/donnemartin/system-design-primer#disadvantages-replication) for points related to both master-slave and master-master.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#disadvantages-replication) Disadvantage(s) : replication
|
||||||
|
|
||||||
|
* There is a potential for loss of data if the master fails before any newly written data can be replicated to other nodes.
|
||||||
|
* Writes are replayed to the read replicas. If there are a lot of writes, the read replicas can get bogged down with replaying writes and can't do as many reads.
|
||||||
|
* The more read slaves, the more you have to replicate, which leads to greater replication lag.
|
||||||
|
* On some systems, writing to the master can spawn multiple threads to write in parallel, whereas read replicas only support writing sequentially with a single thread.
|
||||||
|
* Replication adds more hardware and additional complexity.
|
||||||
|
|
||||||
|
### [](https://github.com/donnemartin/system-design-primer#sources-and-further-reading-replication) Source(s) and further reading: replication
|
||||||
|
|
||||||
|
* [Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/)
|
||||||
|
* [Multi-master replication](https://en.wikipedia.org/wiki/Multi-master_replication)
|
Loading…
Reference in New Issue