System Design Basic Concepts Flashcards
Four main things to care about with system design
Performance, Scalability, Availability, Reliability
What do we call the hardware that runs a system?
Machine
What do we call the hardware a client uses?
Device
What’s the difference between a “service” and a “server”?
A server is an instance of a binary that provides many services
What does API stand for?
Application Programming Interface
What is an API?
It defines how programs interact with each other.
What is a good mental test for scalability?
How well could the program behave if capacity was increased ten-fold?
In what context would you use an Entity-Relationship Diagram?
Designing a database schema
What do you call the set of rules used for an Entity-Relationship Diagram?
Unified Modeling Language
What does UML stand for?
Unified Modeling Language
What is monolithic design?
When all software is built and deployed as a single unit
What are “microservices”?
When software is represented as a collection of independent services that communicate with each other
What is “loose coupling” vs. “tight coupling”?
Loose coupling is when different components and services have minimal dependencies on each other.
Tight coupling is when they’re highly-dependent on each other.
What is “high cohesion” vs. “low cohesion”?
High cohesion is when the logic, methods and classes of a single service are functionally related.
Low cohesion is when the service does a lot of overlapping things and has a vague role.
Why is high cohesion good? Four things.
It’s easier to maintain, deploy, test and understand?
What are the two models of interservice interaction?
Orchestration and Choreography
What is orchestration?
A model of interservice interaction one service is the “orchestrator” and manages communication between services.
What is choreography?
A model of interservice interaction where an event stream holds events and each service may produce events or subscribe (listen to) certain events.
What is persistence?
After data is written to a DB, it is stably stored on non-volatile memory.
Volatile vs. non-volatile memory
Volatile memory is erased when it is powered off, like RAM. Non-volatile is like a hard drive, which maintains data even when powered off.
What does NoSQL stand for?
Not Only SQL
What is NoSQL?
Catch-all term for DBs that don’t store data in tables, such as a key-value collection.
What is a normalized database vs. a de-normalized one?
In a normalized database, data is isolated and non-redundant.
A de-normalized database is when data from one table is copied to be part of another. An example is when you have a FrequencyCap table, and a FrequencyCap field on Campaign.
Vertical vs. Horizontal Scaling
Vertical scaling: Increase the resources of a single machine
Horizontal scaling: Adding more machines
Three examples of ways you can add to vertically scale
CPU, memory, storage
Two examples of ways to horizontally scale a database
Replication, sharding
Replication (in the context of a database)
When you copy data from the primary DB to multiple secondary read-only nodes.
Sharding (in the context of a database)
When you split data into smaller datasets, which you distribute.
Vertical partitioning (in the context of a database)
When data in a DB is sharded by-column.
How do you avoid imbalanced data when sharding a database? That is, one shard having a lot more data than the others.
You hash the shard key.
What does TCP/IP stand for?
Transmission Control Protocol / Internet Protocol
What is TCP/IP?
A model for how data is transmitted around the internet.
What are the four layers of TCP/IP?
Application layer (HTTP)
Transport layer (TCP)
Internet layer (IP)
Network Layer (LAN)
Internet Protocol
Rules for how data packets are routed across networks.
Transmission Control Protocol
Rules for how to deal with network unreliability, so data is reliable.
What does UDP stand for?
User Datagram Protocol
What is UDP?
Protocol for network unreliability handling – it’s a faster version of TCP that is OK with dropping packets?
In what situation might you want to use UDP over TCP?
When you’re OK with dropping packets, like for streaming video
What does SSL stand for?
Secure Sockets Layer
What does TLS stand for?
Transport Layer Security
What’s the relationship between SSL and TLS?
SSL is deprecated in favor of TLS.
What is SSL?
It encrypts connections between the client and server?
What is HTTPS?
It’s HTTP but secured by SSL.
What does DNS stand for?
Domain Name System
What does DNS do?
It resolves domain names to IP addresses.
Proxy
A server relaying traffic to/from the client, and applying logic to that traffic.
Reverse Proxy
A server that accepts requests from clients and forwards them to the server.
What’s the difference between a proxy and a reverse proxy?
Proxy = used by client
Reverse Proxy = used by server
What is the most common use case for a reverse proxy?
Load balancer
System Integration
Term for deciding how components share information
Database Integration
A system integration strategy where the database is the primary means of sharing information between components.
What does REST stand for?
Representational State Transfer
What are the four REST standards?
1: Client and server should be separate and independent
2: Data is represented as resources managed by the server
3: Interfaces support a common set of operations
4: Operations are stateless – the client leaves no context on the server
RESTful API
An API that follows REST standardsE
Explain how HTTP follows REST standards
1: Client and server are separate and independent
2: HTML, CSS, JS, images, etc. are resources managed by the server
3: GET, POST, PUT, DELETE are an interface with a common set of operations
4: Client leaves no context on the server
What does RPC stand for
Remote Procedure Call
What is an RPC
It invokes a routine in a process on some other machine
Stub
Interface that handles RPCs by serializing/deserializing and redirecting the call
What does IDL stand for?
Interface Design Language
What is an IDL for?
It defines how components communicate via RPCs.
What’s a Google example of an IDL?
Protocol buffers (protos)
Distributed System
A group of processes running on different machines and communicating through a network
What are the two key problems you have to solve with a distributed system
Network unreliability
Data inconsistency
What are three causes of network unreliability?
Network faults
Network congestion
Network partitions
Network fault
When machines are unable to communicate with each other for some reason
Network congestion
When there is too much traffic on the network
Network partition
When the network is split into two groups of machines that can’t communicate with each other
Strong consistency
When simultaneous read requests to different nodes are guaranteed to return the same data
Eventual consistency
When nodes are guaranteed to eventually have the same data, albeit not immediately and simultaneously.
What does CAP stand for?
Consistency, Availability, Partition Tolerance
Consistency really means strong consistency
What is the CAP Theorem?
You can’t have all three of
strong consistency
availability
partition tolerance
Problem with a CA system
It can’t tolerate a partition so it’s basically a single-node system
Problem with an AP system
It doesn’t have strong consistency, so a partition could cause stale data in nodes.
Problem with a CP system
It doesn’t guarantee availability, nodes could be shut down during a partition
Five 9s
This is a measure of availability, the uptime of the network being 99.999%
Cluster
A group of nodes
Heartbeat
When nodes send periodic messages to the coordination service to indicate normal operation
Autoscaling
When nodes are automatically added or removed based on traffic
Leader Election
When you have a primary node, and it fails, one of the backup nodes is automatically selected to be the new primary.
Where should you maintain the metadata for a distributed system?
Database
Front-end server
First layer of servers a request reaches
Back-end server
Servers the client doesn’t directly communicate with
Web server
A stateless server that responds to requests from clients (front-end server)
API Gateway
When a web server acts as a single point of access to multiple services, and presents an interface to clients that hides those details
How does web server relate to RPC/REST
REST => used to communicate with clients
RPC => used to communicate with back-end servers
Throttling
When a web server has a maximum capacity over some time window, and rejects requests exceeding that capacity
Load shedding
When a web server discards or re-routes requests that exceed system capacity
Authentication
When a web server validates a user’s identity
Authorization
When a web server determines whether a user has permission to access a particular resource
Degraded dependency
When a downstream server (a dependency of the server being analyzed) isn’t able to handle capacity.
Pushback
When a downstream server that can’t handle capacity lets the web server know “stop sending me stuff”, so that the web server can load shed.
Load Balancer
Distributes incoming network traffic across a group of servers.
What are two places in the system a load balancer might go?
It can go in front of the web server which has multiple instances, and it can go between the web server and the backend servers.
Two types of load balancers
Layer-4 and Layer-7
Layer-4 vs. Layer-7 load balancer
Layer-4 only uses network and transport layer data to make routing decisions.
Layer-7 also uses HTTP request data.
Cache
Temporarily stores a subset of data on a high-speed medium, to improve performance and reduce resource usage.
How much better performance does RAM get vs. SSD?
20x
How much better performance does RAM get vs. HDD?
80x
Why not always use RAM vs. SSD/HDD?
It is way more expensive and it is volatile.
Where in a system would you put a cache?
It can go in any number of places because it’s such a generic concept – you would attach it to a particular service that communicates (directly or indirectly) with a DB, so the service doesn’t always have to communicate with the DB.
Local Cache
Cache located on the same machine as the server.
What is a Local Cache also known as?
Co-Located Cache
Cache Hit / Miss
When data is found (or not found, respectively) in the cache
Cache Invalidation
The strategy for how cache entries are marked as invalid, to be removed.
Most common strategy for cache invalidation
TTL
Cache consistency
In a system with multiple caches, those caches are consistent if they have the same values for the same entries.
Cache replacement policy
How you decide what to remove when the cache is full.
Three most popular cache replacement policies
Least Recently Used
Least Frequently Used
First In First Out
Cache write policy
How you decide how to handle writes to the cache and the DB
Three cache write policies and what they are?
Write-through (write to both cache and DB)
Write-back (write only to cache, separate service syncs to DB)
Write-around (write only to DB, populate cache on cache miss)
Blob Storage
Large volumes of unstructured data, like videos and images
If you have blob storage, how do you still use the DB?
The DB stores metadata about the blobs, and the paths used to access them by-key.
What does CDN stand for?
Content Delivery Network
What is a Content Delivery Network?
It’s a set of geographically-distributed servers where each server copies content from the origin server and distributes it to users.
What is the purpose of a CDN?
To get data geographically closer to users by putting content in a “zone” physically close to the user.
How does the client know to get data from the CDN?
The web server tells it to use some specific CDN server.
What is a common example of when a CDN is used?
For large files, like videos.
Facade
Logical grouping of READ methods in a Read API
What is the main thing to know about Read vs. Write APIs?
That they are often wholly separate interfaces and services.
Fan-out service
Handles one write that triggers multiple writes in multiple destinations.
Two models of fan-out service
Push model: Propagate new items as they’re created
Pull model: Fan-out happens at regular intervals, or on-demand
What does GUID stand for
Globally-unique identifier
What is GUID
It’s a strategy for unique IDs where you just generate enormous numbers and pray that there is no collision.
Snowflake
A strategy for unique IDs where you use the time and server ID as the prefix for a GUID, and then guarantee unique suffix within server at time, so the ID is guaranteed to be unique.
Unique ID service
A service that generates an ID value guaranteed to be unique, often distributed, with servers syncing IDs with each other.
Data warehouse
Stores data from multiple services for analysis.
Data lake
Stores data in its original raw format – a cheap dumping ground for data uploads.
Steps of Map-Reduce:
Map: Send a subset of data to a node that maps input to output
Shuffle: Redistribute outputs to get them grouped by-key on same node
Reduce: Apply reduce function to keyed group of outputs
Functional vs. Non-Functional Testing
Functional testing verifies the correctness of a system on various inputs/outputs
Non-functional testing verifies properties other than correctness
There are many examples of non-functional tests, give three.
Any three of:
Regression test
A/B test
Load test
Stress Test
Endurance test
Security test
Integration test
Tests the interactions between units of software within a group
End-to-end test
Tests the entire system using an external client interacting with the system interface