Scaling to Multi-Tenancy: Logic vs. Automation? Question to Senior Devs.🏗️ I’m currently refactoring a Live Selling management platform from a single-tenant model to a "One User, One Store" multi-tenant architecture. (This will not go to production it is a learning project in Java) I’ve decided on a Shared Database / Shared Schema approach using store_id discriminator columns across all business entities (Orders, Items, Customers etc). I’d love to hear from the architects and senior devs in my network: How are you building your "Logical Walls" in production? 1️⃣ The Manual Approach: Do you trust your team (and yourself) to never forget WHERE store_id = ? in every repository 2️⃣ The Automated Filter: Are you using Hibernate’s @TenantId, global @Filter definitions, or AOP/Interceptors to inject the ID automatically? 3️⃣ Identity Propagation: Are you extracting the Tenant ID strictly from JWT claims, or are you using a custom X-Store-ID header? None of the above... Any suggestion is welcome. I will try it on my end. Looking forward to your war stories and best practices! 🚀 #Java #SpringBoot #SoftwareArchitecture #MultiTenancy #SaaS #BackendEngineering #SpringSecurity
Bhety P.’s Post
More Relevant Posts
-
𝗠𝗼𝘀𝘁 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁 𝗽𝗿𝗼𝗷𝗲𝗰𝘁𝘀 𝗮𝗿𝗲𝗻'𝘁 𝗽𝗿𝗼𝗱𝘂𝗰𝘁𝗶𝗼𝗻-𝗿𝗲𝗮𝗱𝘆. They have controllers. They have CRUD. But they are missing what actually matters. I built a Student Portal API not to tick boxes, but to deeply understand what separates a demo from a deployable system. Here is what that looked like in practice 𝗦𝘁𝗮𝘁𝗲𝗹𝗲𝘀𝘀 𝗔𝘂𝘁𝗵 𝘄𝗶𝘁𝗵 𝗝𝗪𝗧, 𝗻𝗼𝘁 𝘀𝗲𝘀𝘀𝗶𝗼𝗻𝘀 Built a custom JWT filter that intercepts every request before it hits business logic. No session state means horizontally scalable by design. 𝗥𝗲𝗮𝗹 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆, 𝗻𝗼𝘁 𝗰𝗵𝗲𝗰𝗸𝗯𝗼𝘅 𝘀𝗲𝗰𝘂𝗿𝗶𝘁𝘆 BCrypt for password hashing, never plain storage. Spring Security config that locks down endpoints with precision, not a blanket permit-all. 𝗗𝗧𝗢𝘀 𝗼𝘃𝗲𝗿 𝗘𝗻𝘁𝗶𝘁𝘆 𝗘𝘅𝗽𝗼𝘀𝘂𝗿𝗲 Your database schema is not your API contract. Separated entity models from response objects to prevent over-fetching, accidental field leaks, and tight coupling. 𝗣𝗮𝗴𝗶𝗻𝗮𝘁𝗶𝗼𝗻 𝗮𝗻𝗱 𝗦𝗼𝗿𝘁𝗶𝗻𝗴 𝗼𝗻 𝗹𝗮𝗿𝗴𝗲 𝗱𝗮𝘁𝗮𝘀𝗲𝘁𝘀 Most tutorials return everything. Production does not. Built proper paginated responses so the API holds up under real query loads. 𝗖𝗲𝗻𝘁𝗿𝗮𝗹𝗶𝘇𝗲𝗱 𝗘𝘅𝗰𝗲𝗽𝘁𝗶𝗼𝗻 𝗛𝗮𝗻𝗱𝗹𝗶𝗻𝗴 Predictable API behavior means consistent error contracts. One place to catch, format, and return meaningful error responses. 𝗕𝗶𝗴𝗴𝗲𝘀𝘁 𝗶𝗻𝘀𝗶𝗴𝗵𝘁 Authentication is not a login API. It is a request lifecycle problem. Every request must be verified, parsed, and authorized before business logic ever runs. That is what a JWT filter actually solves. 𝗧𝗲𝗰𝗵 𝗦𝘁𝗮𝗰𝗸 Java 17, Spring Boot, Spring Security, JWT, Hibernate, PostgreSQL 𝗖𝘂𝗿𝗿𝗲𝗻𝘁𝗹𝘆 𝗲𝘅𝘁𝗲𝗻𝗱𝗶𝗻𝗴 𝘄𝗶𝘁𝗵 Role-based access control Refresh token rotation Response caching layer If you are building backend projects, stop optimizing for happy paths. 𝗕𝘂𝗶𝗹𝗱 𝗳𝗼𝗿 𝗵𝗼𝘄 𝘀𝘆𝘀𝘁𝗲𝗺𝘀 𝗯𝗲𝗵𝗮𝘃𝗲 𝘂𝗻𝗱𝗲𝗿 𝗿𝗲𝗮𝗹 𝗰𝗼𝗻𝗱𝗶𝘁𝗶𝗼𝗻𝘀. That is what interviewers, code reviewers, and production will test you on. #SpringBoot #Java #BackendDevelopment #SpringSecurity #JWT #SoftwareEngineering #APIDevelopment
To view or add a comment, sign in
-
Clean Architecture fixes this permanently. Here's the rule: dependencies point INWARD only. 📦 Domain layer (innermost) → Pure Java. Zero Spring. Zero DB. → This is where your business rules live. → If this layer compiles, your business logic is correct — regardless of framework. ⚙️ Application layer → @Service classes. Use cases. Orchestration. → Calls domain objects. Talks to repository interfaces. → Never talks directly to controllers or DB. 🔌 Infrastructure layer → @Repository implementations. JPA. External APIs. → The only layer that knows about Spring Data, Hibernate, or AWS. 🌐 Presentation layer → @RestController only. Maps HTTP to use cases. → Converts DTOs. Nothing more. The result? → You can swap your database without touching business logic → You can test domain rules without starting Spring → New teammates understand the codebase in hours, not days This is what I build. Every project. Every time. #CleanArchitecture #Java #SpringBoot #SoftwareDesign #BackendDeveloper #FullStackDeveloper
To view or add a comment, sign in
-
In a Spring Boot application, code is structured into layers to keep things clean, maintainable, and scalable. The most common layers are Controller, Service, and Repository each with a clear responsibility. i)Controller * Entry point of the application. * Handles incoming HTTP requests (GET, POST, etc.). * Accepts request data (usually via DTOs). * Returns response to the client. ii)Service * Contains business logic. * Processes and validates data. * Converts DTO ↔ Entity. iii)Repository * Connects with the database. * Performs CRUD operations. * Works directly with Entity objects. Request Flow (Step-by-Step): Let’s understand what happens when a user sends a request: 1. Client sends request Example: `POST /users` with JSON data. 2. Controller receives request * Maps request to a method. * Accepts data in a DTO. ``` @PostMapping("/users") public UserDTO createUser(@RequestBody UserDTO userDTO) { return userService.createUser(userDTO); } ``` 3. Controller → Service * Passes DTO to Service layer. 4. Service processes data * Applies business logic. * Converts DTO → Entity. ``` User user = new User(); user.setName(userDTO.getName()); ``` 5. Service → Repository * Calls repository to save data. ``` userRepository.save(user); ``` 6. Repository → Database * Data is stored in DB. 7. Response Flow Back * Repository → Service → Controller. * Entity converted back to DTO. * Response sent to client. Why DTO is Used: * Prevents exposing internal entity structure. * Controls input/output data. * Improves security. * Keeps layers independent. Why This Architecture Matters: * Clear separation of concerns * Easier debugging & testing * Scalable and maintainable codebase #Java #Spring #SpringBoot #BackendDevelopment #SoftwareEngineering #JavaDeveloper
To view or add a comment, sign in
-
-
Real-Time Systems Are Built Differently Not all systems are designed for real-time. Traditional applications rely on request-response: Client -> API -> Database -> Response But real-time systems don’t wait. They are built on event-driven architecture, where data flows continuously through the system. Instead of tightly coupled services, you see: • Producers publishing events (user actions, transactions) • Message brokers like Kafka handle streams • Consumers processing data asynchronously • Systems reacting in near real-time This changes everything: • Latency becomes critical • Backpressure and throughput must be managed • Idempotency is required to handle duplicate events • Ordering and partitioning strategies matter • Failures are expected; systems must be resilient In Java ecosystems, this often means: Spring Boot + Kafka Reactive programming (WebFlux) Non-blocking I/O Distributed tracing for observability, because real-time systems are not just about speed. They’re about handling continuous data, at scale, without breaking. And once you start building them, you stop thinking in APIs and start thinking in events. #Java #Kafka #Microservices #EventDrivenArchitecture #RealTimeSystems #BackendDevelopment #C2C #Contract #W2 #FullStack
To view or add a comment, sign in
-
-
🚀 Day 24 — Global Exception Handling Middleware (Clean & Robust APIs) In real-world APIs… Errors are inevitable ❌ 👉 But messy error handling? That’s avoidable 😎 --- 💡 Problem Without Global Handling: ❌ Try-catch everywhere ❌ Duplicate code ❌ Inconsistent error responses ❌ Hard to maintain --- 💡 Solution: Exception Handling Middleware 🔥 👉 Handle all exceptions in one place 👉 Return clean & consistent responses --- 💡 How it works? Request → Middleware → Exception Occurs → Catch → Format Response --- 💡 Example: public class ExceptionMiddleware { private readonly RequestDelegate _next; public ExceptionMiddleware(RequestDelegate next) { _next = next; } public async Task Invoke(HttpContext context) { try { await _next(context); } catch (Exception ex) { await HandleException(context, ex); } } private static Task HandleException(HttpContext context, Exception ex) { context.Response.StatusCode = 500; context.Response.ContentType = "application/json"; var result = JsonSerializer.Serialize(new { Message = "Something went wrong", Detail = ex.Message }); return context.Response.WriteAsync(result); } } --- 💡 Register Middleware: app.UseMiddleware<ExceptionMiddleware>(); --- 💼 Real-World Use Cases: ✔️ Centralized error handling 🔥 ✔️ Consistent API response format ✔️ Logging errors ✔️ Better debugging --- ⚠️ Common Mistakes: ❌ Exposing sensitive error details ❌ Not logging exceptions ❌ Handling only specific exceptions ❌ Wrong middleware order --- 🔥 Best Practices: ✔️ Use structured error response ✔️ Log errors properly ✔️ Hide sensitive details in production ✔️ Place middleware at top of pipeline --- 👉 Pro Tip 🔐 In production: ✔️ Show generic message ✔️ Log full error internally --- 👉 In simple terms: Exception Middleware = One place to handle all errors 🚀 --- 💬 Do you use global exception handling or try-catch in controllers? — Sandip Chaudhary #DotNet #ASPNetCore #ExceptionHandling #Middleware #WebAPI #BackendDevelopment #SystemDesign #CleanCode #LearningInPublic #Developers #Coding #SoftwareEngineering #TechCommunity #CareerGrowth #KnowledgeSharing #SandipChaudhary
To view or add a comment, sign in
-
-
Recently, I’ve been working on backend automation using Spring Boot and Java, focusing on improving how structured data flows between systems. A big part of the challenge has been handling semi-structured inputs and transforming them into consistent, usable data for downstream processes. Some of the areas I’ve been exploring: • Extracting metadata through tagging strategies • Working with hybrid data models (structured entities + flexible JSON) • Designing logic that adapts based on the available data instead of forcing rigid structures • Building automation flows that stay maintainable as requirements evolve This experience has pushed me to think more about trade-offs in data modeling and how to design systems that are resilient to change. Always interested in connecting with others working on backend systems, automation, or data-driven workflows. #Java #SpringBoot #BackendDevelopment #Automation #SoftwareEngineering
To view or add a comment, sign in
-
💼 𝐉𝐚𝐯𝐚 𝐁𝐚𝐜𝐤𝐞𝐧𝐝 𝐃𝐞𝐯𝐞𝐥𝐨𝐩𝐞𝐫 – 𝐋𝟐 𝐓𝐞𝐜𝐡𝐧𝐢𝐜𝐚𝐥 (𝐎𝐧𝐥𝐢𝐧𝐞 𝐅𝐄𝐁 𝟐𝟎, 𝟐𝟎𝟐𝟔) #𝐋𝐓𝐌 👉 This round focused on real-time scenarios + problem solving 📌 Questions were based on production issues & design thinking 📌 Next post → Client round experience 𝐄𝐱𝐩𝐞𝐫𝐢𝐞𝐧𝐜𝐞: 𝟑–𝟓 𝐘𝐞𝐚𝐫𝐬 𝐓𝐞𝐜𝐡 𝐒𝐭𝐚𝐜𝐤: 𝐉𝐚𝐯𝐚, 𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭, 𝐌𝐢𝐜𝐫𝐨𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬, 𝐒𝐐𝐋 𝐈𝐧𝐭𝐞𝐫𝐯𝐢𝐞𝐰 𝐐𝐮𝐞𝐬𝐭𝐢𝐨𝐧𝐬 𝐀𝐬𝐤𝐞𝐝 1️⃣ If API response time suddenly increased, how will you debug? 2️⃣ In case one microservice is down, then how will you handle fallback? 3️⃣ If duplicate records are getting inserted, then how do you find the root cause & fix it? 4️⃣ When there is a high DB load, then how do you optimize queries & indexing? 5️⃣ Scenario: Memory leak in production → how will you identify? 6️⃣ Write thread-safe caching mechanism (Java) 7️⃣ Group employees by dept & get max salary with Stream API 8️⃣ Remove duplicates & sort custom object with Stream API 9️⃣ Convert List<List<String>> → List<String> using flatMap 🔟 Write Spring Boot REST API with validation & exception handling 1️⃣1️⃣ Write down code to implement global exception handling 1️⃣2️⃣ Write JPA custom query (JPQL + Native) 1️⃣3️⃣ In case the transaction rollback is not happening, what will be the reason? 1️⃣4️⃣ Explain @Transactional propagation with use case. 1️⃣5️⃣ Design API for high concurrent users (rate limiting, caching) 1️⃣6️⃣ When multiple services are updating the same data, how do you handle data consistency? 1️⃣7️⃣ How will you implement Circuit Breaker in Spring Boot? 1️⃣8️⃣ Difference between Feign vs WebClient (which in high load?) 1️⃣9️⃣ Scenario: Need async processing → how to implement? 2️⃣0️⃣ ExecutorService use case in real-time project 💼 𝑭𝒐𝒍𝒍𝒐𝒘 & 𝑪𝒐𝒏𝒏𝒆𝒄𝒕 🔗 For more Java, Spring Boot & Interview Prep content 🚀 👉 https://lnkd.in/dXeqv5Bf #Java #SpringBoot #Microservices #JavaDeveloper #BackendDeveloper #SQL #InterviewPreparation #CodingInterview #SystemDesign #TechCareer #LearningEveryday #SpringFramework #TechCommunity Capgemini Infosys Tata Consultancy Services L&T Technology Services
To view or add a comment, sign in
-
🚀 Deep Internal Flow of a REST API Call in Spring Boot 🧭 1. Entry Point — The Gatekeeper DispatcherServlet is the front controller. Every HTTP request must pass through this single door. FLOW: Client → Tomcat (Embedded Server) → DispatcherServlet 🗺️ 2. Handler Mapping — Finding the Target DispatcherServlet asks: “Who can handle this request?” It consults: * RequestMappingHandlerMapping This scans: * @RestController * @RequestMapping FLOW : DispatcherServlet → HandlerMapping → Controller Method Found ⚙️ 3. Handler Adapter — Executing the Method Once the method is found, Spring doesn’t call it directly. It uses: * RequestMappingHandlerAdapter Why? Because it handles: * Parameter binding * Validation * Conversion FLOW : HandlerMapping → HandlerAdapter → Controller Method Invocation 🧭 4. Request Flow( Forward ): Controller -> Service Layer (buisiness Logic) -> Repository Layer -> DataBase 🔄 5. Response Processing — The Return Journey Now the response travels back upward: Repository → Service → Controller → DispatcherServlet -> Tomcat -> Client. ———————————————— ⚡ Hidden Magic (Senior-Level Insights) 🧵 Thread Handling * Each request runs on a separate thread from Tomcat’s pool 🔒 Transaction Management * Managed via @Transactional * Proxy-based AOP behind the scenes 🎯 Dependency Injection * Beans wired by Spring IoC container 🧠 AOP (Cross-Cutting) * Logging, security, transactions wrapped around methods ⚡ Performance Layers * Caching (Spring Cache) * Connection pooling (HikariCP) ———————————————— 🧠 The Real Insight At junior level i thought: 👉 “API call hits controller” At senior level i observe: 👉 “A chain of abstractions collaborates through well-defined contracts under the orchestration of DispatcherServlet” #Java #SpringBoot #RestApi #FullStack #Developer #AI #ML #Foundations #Security
To view or add a comment, sign in
-
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development