- Big O Notation
- RESTful Web Services
- Idempotency
- Fail Tolerance
- Scalability
- Transactions
- Stateless & Stateful
- Eventual Consistency
- System Design
- Architectural Patterns
- CQRS - Command Query Responsibility Segregation
- Publish-Subscribe
- Event Sourcing
- Architectural Patterns
Big O notation is a way to describe the efficiency of algorithms, specifically in terms of time and space as the input size grows.
O(1) - Constant Time: The runtime doesn't change with the input size.
Example: Accessing an element in an array.
public static int getElement(int[] array, int index) {
return array[index]; // O(1)
}
O(n) - Linear Time: The runtime increases linearly with the input size.
Example: Linear search in an array.
public static int linearSearch(int[] array, int target) {
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
return i; // O(1)
}
}
return -1; // O(1)
}
O(n^2) - Quadratic Time: The runtime increases quadratically with the input size.
Example: Bubble sort algorithm.
public static int linearSearch(int[] array, int target) {
for (int i = 0; i < array.length; i++) {
if (array[i] == target) {
return i; // O(1)
}
}
return -1; // O(1)
}
Think of Big O notation as a scale of efficiency:
- O(1) is super fast.
- O(n) is moderate.
- O(n^2) is slower as the input size grows.
Big O notation provides a high-level understanding of algorithm performance by focusing on the most significant factor that impacts runtime or space usage.
REST (Representational State Transfer) is an architecture style for designing networked applications using the principles of HTTP. Here are the key concepts:
- Resources :
- Represent data or services, identified by unique URLs.
- Example:
https://api.example.com/users/123
represents the user with ID 123.
- HTTP Methods :
- GET : Retrieves data from a resource.
- POST : Creates a new resource.
- PUT : Updates an existing resource.
- DELETE : Deletes a resource.
- Representations :
-
Data can be represented in various formats, such as JSON or XML.
-
JSON Example: jsonCopiar
{ "id": 123, "name": "John Doe", "email": "[email protected]" }
-
- Statelessness :
- Each client-server interaction must contain all the necessary information to process the request, without relying on stored context on the server.
- HATEOAS (Hypermedia As The Engine Of Application State) :
-
Clients interact with the application through hypermedia provided by the server, allowing navigation through resources.
-
Example: jsonCopiar
{ "id": 123, "name": "John Doe", "links": [ {"rel": "self", "href": "/users/123"}, {"rel": "friends", "href": "/users/123/friends"} ] }
-
- Endpoints :
-
URLs that represent resources and the possible operations.
-
Example: Copiar
GET /users/ -> list of users POST /users/ -> create a new user GET /users/123 -> details of user with ID 123 PUT /users/123 -> update user with ID 123 DELETE /users/123 -> delete user with ID 123
-
- Simplicity: Using HTTP makes it easy to understand and use.
- Scalability: Stateless architecture allows for horizontal scaling.
- Flexibility: Supports various data formats like JSON, XML.
@RestController
@RequestMapping("/users")
public class UserController {
@GetMapping("/{id}")
public ResponseEntity<User> getUserById(@PathVariable Long id) {
User user = userService.findById(id);
return ResponseEntity.ok(user);
}
@PostMapping("/")
public ResponseEntity<User> createUser(@RequestBody User user) {
User createdUser = userService.save(user);
return ResponseEntity.status(HttpStatus.CREATED).body(createdUser);
}
}