What is REST controller? REST stands for REpresentation State Transfer. A web controller is a logical component that is responsible for navigation of all operations related to a resource. If you have a ProductController in your application, this ProductController will be responsible for: - 1. Creating new product 2. Updating existing product 3. Deleting a product 4. Getting a product 5. Getting all products Write Product class package wealthManager.models; import java.io.Serializable; public class Product implements Serializable { private final String name ; private int price ; public Product (String name, int price) { this . name = name; this . price = price; } public void setPrice ( int price){ this . price = price; } public String getName () { return name ; } public int getPrice () { return price ; } } Write ProductController class package wealthManager.rest; import jakarta.annotation. PostConstruct ; im...
Problem link: https://leetcode.com/problems/invert-binary-tree/ Question type: Easy Code class Solution { public TreeNode invertTree ( TreeNode root ) { if (root == null ) { return root; } TreeNode left = root . left ; TreeNode right = root . right ; // inversion logic root . left = right; root . right = left; // process the sub trees invertTree (left); invertTree (right); return root; } } Test Results
Dependency Injection - the concept I know, DI is managed by Spring IoC container in Spring boot Thread safety is ensured by synchronization techniques ** Scalable REST API ** Use pagination for large datasets Caching for high frequency requests API rate limiting to prevent abuse ** SQL vs NoSQL ** Structured data, relations, tables -> SQL -> ACID props Unstructured, frequently changing -> NoSQL -> Order data ** Auth in microservices ** Centralized auth server will issue JWT tokens -> stateless auth Each Microservices verifies token and does role based authorization ** Error logging and monitoring ** use centralized logging like ELK structured logging format -> JSON distributed tracing OpenTelemetry to track requests across services setup alerts for critical errors via Grafana ** Optimize database queries ** use indexes, avoid Select * , query caching, normalized table structures, optimized joins, analyse query execution plans (filtering should be done befor...
Comments
Post a Comment
Share your thoughts here...