System Design Flashcards
What is a semaphore
Non negative integer variable shared between various threads
It has 2 operations: Wait & Signal
Used to control access to a common resource by multiple processes or threads
What is a mutex
MUTUAL EXCLUSION
Specific kind of semaphore that is a locking mechanism
Used to ensure exclusive access to a single resource
What is a thread
Smallest sequence of a programmed instruction that can be managed by a single scheduler
It is an execution unit that contains a thread ID, program counter, register set and track
Types of load balancer
Hardware v software
Layer 4 v Layer 7
4: operates on transport layer, routes traffic based on IP address and port
7: operates on app layer and routes based on content such as URL paths or HTTP headers
Examples of load balancing algorithms
Round robin: distributed requests sequentially among servers
Least connections
IP hash: determines server based on IP address of client
Weighted algos: distributes to servers based on weights
What is a scheduler? Give examples of types?
System component responsible for managing the execution of processes and threads
Job scheduler: long term
CPU scheduler: short term
Medium term
Scheduling algos
First come first served
Shortest Job next
Prioritising
Round robin
Multilevel: split into sub queues with own algo
Multilevel feedback: same as multilevel but allows movement between sub queues based on some criteria
What is a RESTful API
Representational state transfer
Uses stateless communication
Client server architecture
Cacheable responses
Uniform interfaces
Layered system: client (usually) can’t tell if is communicating with end server
Alternatives to RESTful
SOAP (simple object access protocol)
GRAPH QL
gRPC Google Remote Procedure Calls
OData open data protocol
Why use RESTful
Simplicity: uses standard HTTP methods
Scalability: stateless nature allows
Flexibility: can handle many type of calls and return in many formats
Portability: can access from any environment that supports HTTP
Low bandwidth
Steps to make RESTful
- Define resources
- Define HTTP methods
POST GET DELETE - use status codes to represent outcome of posts
- Ensure statelessness
Each call should contain all necessary info without relying on stored user info - Implement error handling
- Documentation
- Versioning
- Security considerations
Implement rate limiting, input validation, maybe auth - Response formatting
Use JSON
Problems of SOAP
Simple object access protocol
Complexity, heavier than RESTful
Verbosity
Flexibility, often protocol dependent
Limitations of GraphQL
Client side caching can be difficult due to query complexity
File upload is more complex
More overheads (processing time)
Steeper learning curve
Limitations of gRPC
Google remote procedure calls
Its use of HTTP/2 is not natively support in all web browsers
Readability: uses binary format (which is efficient)
Complexity
Ecosystem: not as mature but is growing
Steps for designing a system
1) scope problem: determine parameters
2) determine assumptions: q&a
3) draw out simplified system
4) identify issues
5) redesign