Single server setup
Request Flow
- Users access websites through domain names, such as api.mysite.com. Usually, the Domain Name System (DNS) is a paid service provided by 3rd parties and not hosted by our servers.
- Internet Protocol (IP) address is returned to the browser or mobile app. In the example, IP address 15.125.23.214 is returned.
- Once the IP address is obtained, Hypertext Transfer Protocol (HTTP) [1] requests are sent directly to your web server.
- The web server returns HTML pages or JSON response for rendering.
Trafic source
- Web
- Mobile
Database
RDBMS: Relational Database Management System
- Relational
- Non-Relational
Scaling
Vertical Scaling
Adding more CPU, RAM, etc.
#horizontal-scale
add servers
Load Balancing
In previous step 3, might routed to different private IP address.
Database Replication
A master database generally only supports write operations.
- All the data-modifying commands like insert, delete, or update must be sent to the master database. A slave database gets copies of the data from the master database and only supports read operations.
Cache
Cache used to store result of existing responses. Use Cache when:
- data frequently read but not modify
- expiration policy is set
- data is consistent
- try to avoid #SPOF A single point of failure (SPOF) is a part of a system that, if it fails, will stop the entire system from working”
CDN
Content Delivery Network
def
Dispersed servers used to deliver static content
Considerations
- Cost
- Cache Expire
- What to do when CDN outage
- Invalidating files
Update
Stateless web tier
#horizontal-scale A stateful server remembers client data (state) from one request to the next. A stateless server keeps no state information
Message Queue
A message queue is a durable component, stored in memory, that supports asynchronous communication
Architecture
Producers/Publishers
Create messages and publish them to a queue.
Consumers/Subscribers
connect to the queue and perform actions defined by messages.
Database Scaling
#horizontal-scale Sharding
Def
Sharding separates large databases into smaller, more easily managed parts called shards. Each shard shares the same schema, though the actual data on each shard is unique to the shard.
Factors
Most important: the choice of the sharding key.
Sharding key (known as a partition key) consists of one or more columns that determine how data is distributed.
Challenges
- Resharding: when data is exceed shard length
- Celebrity Problem: some data would be read overwhelmed times than normal data
- Hard to perform join operations across database shards.