💡 Day 14 of my 𝗝𝗮𝘃𝗮 𝗕𝗮𝗰𝗸𝗲𝗻𝗱 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗼𝗳 𝘁𝗵𝗲 𝗗𝗮𝘆 𝘀𝗲𝗿𝗶𝗲𝘀: 🧠 Question: Your Spring Boot microservice calls an external payment API. Sometimes the payment API responds within 200 ms, but during peak hours it starts taking 3–5 seconds. This slowdown is causing your API to become slow, and users are complaining about delays. 👉 As a backend engineer, what practical steps would you take to protect your service from slow downstream APIs? ✅ Answer: To handle a slow external API without affecting your users, apply these strategies: 1. 𝐒𝐞𝐭 𝐚𝐠𝐠𝐫𝐞𝐬𝐬𝐢𝐯𝐞 𝐭𝐢𝐦𝐞𝐨𝐮𝐭𝐬 Never wait 5 seconds for a dependency. Set: • Connection timeout → short • Read timeout → short Example: 500 ms–1 sec 2. 𝐔𝐬𝐞 𝐂𝐢𝐫𝐜𝐮𝐢𝐭 𝐁𝐫𝐞𝐚𝐤𝐞𝐫 (𝐑𝐞𝐬𝐢𝐥𝐢𝐞𝐧𝐜𝐞4𝐣) If the payment service becomes slow or fails repeatedly: • Open the circuit • Stop calling it temporarily • Return fallback immediately This prevents your threads from being blocked. 3. 𝐀𝐝𝐝 𝐁𝐮𝐥𝐤𝐡𝐞𝐚𝐝 𝐩𝐚𝐭𝐭𝐞𝐫𝐧 Isolate payment API calls into a separate thread pool. If payment is slow, it will only block its own pool, not the entire service. 4. 𝐔𝐬𝐞 𝐚𝐬𝐲𝐧𝐜𝐡𝐫𝐨𝐧𝐨𝐮𝐬 𝐜𝐚𝐥𝐥 + 𝐝𝐞𝐟𝐞𝐫𝐫𝐞𝐝 𝐫𝐞𝐬𝐩𝐨𝐧𝐬𝐞 Don’t block your main request thread. Your API can respond quickly with: • “Payment is in processing” • Notify user when complete 5. 𝐂𝐚𝐜𝐡𝐞 𝐬𝐭𝐚𝐛𝐥𝐞 𝐫𝐞𝐬𝐩𝐨𝐧𝐬𝐞𝐬 If API provides static data (token, config), cache it to reduce external calls. 6. 𝐀𝐝𝐝 𝐟𝐚𝐥𝐥𝐛𝐚𝐜𝐤 𝐩𝐥𝐚𝐧 Example: • Retry with exponential backoff • Switch to secondary payment provider • Return partial response ✅ 𝘚𝘮𝘢𝘳𝘵 𝘵𝘪𝘮𝘦𝘰𝘶𝘵 + 𝘤𝘪𝘳𝘤𝘶𝘪𝘵 𝘣𝘳𝘦𝘢𝘬𝘦𝘳 + 𝘣𝘶𝘭𝘬𝘩𝘦𝘢𝘥 → 𝘺𝘰𝘶𝘳 𝘴𝘦𝘳𝘷𝘪𝘤𝘦 𝘴𝘵𝘢𝘺𝘴 𝘧𝘢𝘴𝘵 𝘦𝘷𝘦𝘯 𝘸𝘩𝘦𝘯 𝘥𝘦𝘱𝘦𝘯𝘥𝘦𝘯𝘤𝘪𝘦𝘴 𝘢𝘳𝘦 𝘴𝘭𝘰𝘸. ⚙️ See you tomorrow for Day 15 👋 #Java #SpringBoot #Microservices #Resilience4j #SystemDesign #BackendDeveloper #Performance #ContinuousLearning #QuestionOfTheDay
How to handle slow external APIs in Spring Boot microservices
More Relevant Posts
-
Do you think your REST APIs are production-grade? We have been developing REST APIs for ages. But still most of the code bases do not follow the standard rules of developing REST endpoints. Even, sometimes senior developers make these mistakes. So how do we make our APIs production grade? Let's see the common mistakes and what can be the work around. The difference between a "working" API and a "scalable" one often comes down to 5 specific patterns. If your Spring Boot controllers look clean but expose your database entities, you might be building a maintenance nightmare. Here is the blueprint for moving from functional to professional APIs: ❌ The Mistake: Exposing Database Entities ✅ The Fix: Use dedicated DTOs to decouple your API contract from your DB schema. ❌ The Mistake: Returning 200 OK for errors ✅ The Fix: Use consistent, standard HTTP status codes (409 Conflict, 404 Not Found) so clients can handle them automatically. ❌ The Mistake: Unbounded findAll() lists ✅ The Fix: Implement pagination from day one to prevent memory crashes. ❌ The Mistake: No versioning strategy ✅ The Fix: Use URL or Header versioning before the first deploy to avoid breaking changes later. I have written an article that provides a fantastic breakdown of the code behind these patterns. A must-read for backend engineers. https://lnkd.in/gF5EDTgJ #Java #RestAPI #SoftwareEngineering #BestPractices #Backend
Stop Designing REST APIs Like a Junior: 5 Patterns Senior Engineers Use Instead blog.stackademic.com To view or add a comment, sign in
-
💡 Day 40 of my 𝗝𝗮𝘃𝗮 𝗕𝗮𝗰𝗸𝗲𝗻𝗱 𝗤𝘂𝗲𝘀𝘁𝗶𝗼𝗻 𝗼𝗳 𝘁𝗵𝗲 𝗗𝗮𝘆 𝘀𝗲𝗿𝗶𝗲𝘀: 🧠 Question: In a microservices system, a single user request passes through multiple services. When latency increases or an error occurs, it’s hard to know which service caused the problem. 👉 How does distributed tracing help, and how is it implemented in Spring Boot microservices? ✅ Answer: 𝗪𝗵𝗮𝘁 𝗶𝘀 𝗗𝗶𝘀𝘁𝗿𝗶𝗯𝘂𝘁𝗲𝗱 𝗧𝗿𝗮𝗰𝗶𝗻𝗴? A technique to track a single request end-to-end as it flows through multiple microservices. Each request carries a 𝒕𝒓𝒂𝒄𝒆𝑰𝒅 and 𝒔𝒑𝒂𝒏𝑰𝒅, allowing all related logs and timings to be linked. 𝗪𝗵𝘆 𝗶𝘁’𝘀 𝗶𝗺𝗽𝗼𝗿𝘁𝗮𝗻𝘁: ✔ Identifies which service is slow ✔ Helps debug errors across services ✔ Shows call flow and latency breakdown ✔ Essential for production debugging 𝗛𝗼𝘄 𝗶𝘁 𝘄𝗼𝗿𝗸𝘀: 𝐓𝐫𝐚𝐜𝐞 𝐈𝐃 : One ID shared across all services for a request. 𝐒𝐩𝐚𝐧 : Each service call creates a span with timing info. 𝗛𝗼𝘄 𝘁𝗼 𝗶𝗺𝗽𝗹𝗲𝗺𝗲𝗻𝘁 𝗶𝗻 𝗦𝗽𝗿𝗶𝗻𝗴 𝗕𝗼𝗼𝘁: ✔ Use Spring Cloud Sleuth / Micrometer Tracing ✔ Export traces to Zipkin, Jaeger, or Tempo ✔ Traces propagate automatically via HTTP headers ✔ View full request flow visually in tracing UI 𝗘𝘅𝗮𝗺𝗽𝗹𝗲 𝗶𝗻𝘀𝗶𝗴𝗵𝘁: “API took 2s → UserService (50ms) → OrderService (1.7s) → PaymentService (200ms)” → bottleneck found instantly. ✅ 𝘿𝙞𝙨𝙩𝙧𝙞𝙗𝙪𝙩𝙚𝙙 𝙩𝙧𝙖𝙘𝙞𝙣𝙜 𝙩𝙪𝙧𝙣𝙨 “𝙨𝙤𝙢𝙚𝙩𝙝𝙞𝙣𝙜 𝙞𝙨 𝙨𝙡𝙤𝙬” 𝙞𝙣𝙩𝙤 “𝙩𝙝𝙞𝙨 𝙚𝙭𝙖𝙘𝙩 𝙨𝙚𝙧𝙫𝙞𝙘𝙚 𝙖𝙣𝙙 𝙘𝙖𝙡𝙡 𝙞𝙨 𝙨𝙡𝙤𝙬”. ⚙️ See you tomorrow for Day 41 👋 #Java #SpringBoot #Microservices #Observability #DistributedTracing #BackendDeveloper #SystemDesign #ContinuousLearning #QuestionOfTheDay
To view or add a comment, sign in
-
REST API development is not about exposing endpoints. It is about building reliable, scalable, and secure communication between systems. A production-ready REST API reflects: • Well-designed resources and clear contracts • Correct use of HTTP methods and status codes • Graceful error handling instead of silent failures • Stateless architecture for scalability • Security at every layer, not as an afterthought Frameworks like Spring Boot accelerate development, but strong REST fundamentals define engineering quality. Developers who understand these principles can adapt quickly, build resilient systems, and deliver real business value. Consistency, clarity, and correctness — that is what great APIs are built on. -->Frameworks help you build faster. Fundamentals help you build right. That difference defines strong backend engineers. #RESTAPI #BackendEngineering #SoftwareDevelopment #APIDesign #SpringBoot #JavaDeveloper #TechCareers
To view or add a comment, sign in
-
𝐈𝐟 𝐘𝐨𝐮’𝐫𝐞 𝐏𝐫𝐞𝐩𝐚𝐫𝐢𝐧𝐠 𝐒𝐲𝐬𝐭𝐞𝐦 𝐃𝐞𝐬𝐢𝐠𝐧, 𝐋𝐞𝐚𝐫𝐧 𝐒𝐚𝐠𝐚 𝐁𝐞𝐟𝐨𝐫𝐞 𝐄𝐯𝐞𝐫𝐲𝐭𝐡𝐢𝐧𝐠 𝐄𝐥𝐬𝐞 In a monolith, a transaction is simple. One DB → commit or rollback. But in microservices, that comfort disappears. A payment workflow I was working on needed 3 services: 𝐃𝐞𝐛𝐢𝐭 𝐰𝐚𝐥𝐥𝐞𝐭 𝐔𝐩𝐝𝐚𝐭𝐞 𝐥𝐞𝐝𝐠𝐞𝐫 𝐒𝐞𝐧𝐝 𝐜𝐨𝐧𝐟𝐢𝐫𝐦𝐚𝐭𝐢𝐨𝐧 All three had to succeed together or fail together. So I did the rookie thing: Tried to force a single transaction across services. Looked good on paper. Impossible in production. Because: 𝐝𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭 𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬 𝐝𝐢𝐟𝐟𝐞𝐫𝐞𝐧𝐭 𝐃𝐁𝐬 𝐧𝐞𝐭𝐰𝐨𝐫𝐤 𝐟𝐚𝐢𝐥𝐮𝐫𝐞𝐬 𝐩𝐚𝐫𝐭𝐢𝐚𝐥 𝐜𝐨𝐦𝐦𝐢𝐭𝐬 𝐫𝐞𝐭𝐫𝐢𝐞𝐬 𝐫𝐚𝐜𝐞 𝐜𝐨𝐧𝐝𝐢𝐭𝐢𝐨𝐧𝐬 One failure = inconsistent state. That’s when I learned the painful truth: 𝐓𝐡𝐞𝐫𝐞 𝐢𝐬 𝐧𝐨 𝐠𝐥𝐨𝐛𝐚𝐥 𝐫𝐨𝐥𝐥𝐛𝐚𝐜𝐤 𝐛𝐮𝐭𝐭𝐨𝐧 𝐢𝐧 𝐝𝐢𝐬𝐭𝐫𝐢𝐛𝐮𝐭𝐞𝐝 𝐬𝐲𝐬𝐭𝐞𝐦𝐬. The correct approach isn’t “rollback everything”. It’s compensate the previous action. That’s when Sagas finally made sense: step 1 succeeds → move ahead step 2 succeeds → move ahead step 3 fails → undo step 2 undo step 1 Not reversing the transaction in one shot — but reversing each step safely. This changed how I think about distributed systems: 𝐀𝐭𝐨𝐦𝐢𝐜𝐢𝐭𝐲 𝐝𝐨𝐞𝐬𝐧’𝐭 𝐬𝐜𝐚𝐥𝐞. 𝐂𝐨𝐦𝐩𝐞𝐧𝐬𝐚𝐭𝐢𝐨𝐧 𝐝𝐨𝐞𝐬. If you’re preparing for backend interviews, learn when to use: 2𝐏𝐂 (𝐫𝐚𝐫𝐞 𝐢𝐧 𝐡𝐢𝐠𝐡-𝐬𝐜𝐚𝐥𝐞 𝐬𝐲𝐬𝐭𝐞𝐦𝐬 – 𝐜𝐨𝐨𝐫𝐝𝐢𝐧𝐚𝐭𝐢𝐨𝐧 𝐛𝐨𝐭𝐭𝐥𝐞𝐧𝐞𝐜𝐤) 𝐒𝐚𝐠𝐚 𝐩𝐚𝐭𝐭𝐞𝐫𝐧 (𝐬𝐭𝐚𝐧𝐝𝐚𝐫𝐝 𝐢𝐧 𝐦𝐢𝐜𝐫𝐨𝐬𝐞𝐫𝐯𝐢𝐜𝐞𝐬) 𝐈𝐝𝐞𝐦𝐩𝐨𝐭𝐞𝐧𝐭 𝐜𝐨𝐦𝐩𝐞𝐧𝐬𝐚𝐭𝐢𝐨𝐧𝐬 Understanding transactions in microservices is the difference between writing APIs and designing systems. 👇 𝐂𝐨𝐦𝐦𝐞𝐧𝐭 𝐢𝐟 𝐲𝐨𝐮 𝐰𝐚𝐧𝐭 𝐚 𝐩𝐨𝐬𝐭 𝐨𝐧 𝐒𝐚𝐠𝐚 𝐢𝐦𝐩𝐥𝐞𝐦𝐞𝐧𝐭𝐚𝐭𝐢𝐨𝐧 𝐧𝐞𝐱𝐭. #SystemDesign #Microservices #DistributedSystems #Java #BackendDevelopment #TechnicalInterviews
To view or add a comment, sign in
-
Complete API Roadmap for Developers (2025 Guide) A clear and structured API Roadmap designed to help developers—from beginners to professionals—understand the full lifecycle of API development. This roadmap covers everything: ✨ API fundamentals ✨ Architectures (REST, GraphQL, gRPC, WebSockets & more) ✨ Security essentials ✨ Best-practice design principles ✨ Documentation tools ✨ Testing workflows ✨ API management strategies ✨ Implementation frameworks like Flask, Express, Spring Boot & FastAPI Perfect for anyone looking to level up their backend or integration skills. Save & share with someone learning APIs! API Roadmap API Development Backend Development REST API GraphQL API Testing API Security Software Architecture Dev Tools Microservices #API #BackendDevelopment #APISecurity #Developers #Roadmap #SoftwareEngineering #Microservices #WebDevelopment #TechLearning #ProgrammingSkills #FastAPI #SpringBoot yogesh.sonkar.in@gmail.com
To view or add a comment, sign in
-
-
One bug can hide quietly in a distributed system for weeks. The real challenge isn’t fixing it. It’s finding it. When you build microservices, the biggest pain isn’t coding the services. It’s tracing what actually happened when something breaks. I learned this while working on a multi-service Spring Boot project. A simple request travelled across User, Product, and Order services. If anything failed in the middle, the logs told different stories on each service. That’s when I started using Correlation IDs. Here’s the simple idea: Every incoming request gets a unique ID. That ID travels through every service that handles the request. All logs use it. Example using a filter in Spring Boot: public class CorrelationIdFilter implements Filter { @Override public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String id = request.getHeader("X-Correlation-Id"); if (id == null) { id = UUID.randomUUID().toString(); } MDC.put("correlationId", id); chain.doFilter(req, res); MDC.clear(); } } Now every log line looks like this: correlationId=8f23a1 OrderService - Payment failed due to timeout Suddenly, debugging became easier than ever. No more jumping between 3 log files guessing what happened. One ID. One story. Good backend engineering isn’t just building features. It’s building systems you can understand under pressure. Want me to share a full example of distributed tracing with Sleuth or OpenTelemetry next? #Java #SpringBoot #BackendDevelopment #Microservices #Debugging #Logging #SoftwareEngineering #DistributedSystems
To view or add a comment, sign in
-
-
Most backend systems don’t fail because of bad code. They fail because of silent assumptions. I learned this while reviewing a Spring Boot service that looked perfect on the surface. Clean layers. Proper naming. Tests passing. Yet production issues kept coming. The real problem was not code quality. It was architecture assumptions that were never questioned. Here are a few assumptions I now challenge early: 1️⃣ This service will always be fast Every dependency slows down eventually. Databases. Networks. Third party APIs. Architecture should expect slowness, not deny it. 2️⃣ This API will not get much traffic Every internal API becomes public someday. Growth always finds the weakest path. 3️⃣ Failures are rare Failures are normal. What matters is whether they are isolated or contagious. 4️⃣ We can refactor later Later usually means never. Architecture debt compounds faster than code debt. What changed my approach was this mindset shift: Design for how the system behaves when things go wrong, not when everything is perfect. That single shift reduced incidents more than any refactoring sprint ever did. Architecture is not about patterns or diagrams. It is about predicting stress before stress arrives. #ArchitectureThinking #BackendEngineering #SystemDesign #SpringBoot #Java #SoftwareEngineering #TechLeadership
To view or add a comment, sign in
-
-
Don't underestimate the power of a well-structured Monolith. 🏗️ In a tech world obsessed with Microservices, working on my recent full-stack project taught me a valuable lesson: Complexity isn't always better. I made the conscious decision to architect the backend as a Monolith, and frankly, it was a masterclass in understanding system behavior. Why I loved this approach: 🔹 End-to-End Visibility: Debugging is seamless when you can trace a request from the controller to the database without hopping network boundaries. 🔹 Efficiency: No network latency between services means snappy performance for the core logic. 🔹 Simplicity: Deployment was straightforward, allowing me to focus on feature building rather than orchestration headaches. Building this system gave me a granular view of how different modules interact within a single execution environment. It wasn't just about writing code; it was about seeing the "pulse" of the application in one place. Sometimes, a clean, modular Monolith is the most efficient solution for the problem at hand. Has anyone else found joy in the simplicity of a Monolith recently? 👇 #SystemDesign #BackendDevelopment #SoftwareEngineering #Monolith #LearningByDoing #Java #SpringBoot
To view or add a comment, sign in
-
😬 The first time I saw a backend fail in production, the bug wasn’t the problem. The error handling was. Different endpoints. Different error messages. Same failure — zero clarity. Clients didn’t know what broke. Logs didn’t help. Fixing it took longer than writing the feature. That’s when I realized something important. 🧠 Exception handling is not boilerplate. It’s architecture. ❌ What usually goes wrong: • Controllers throw random exceptions • Error responses change from API to API • Stack traces leak into client responses • 4xx and 5xx errors get mixed ✅ What I do differently now: • Centralized global exception handling • One consistent error response format • Clear separation between client vs server errors • Internal details logged, never exposed Failures are inevitable. Confusion is optional. Clean exception handling doesn’t just help developers. It protects users, clients, and on-call engineers. That’s real backend reliability. #Java #SpringBoot #BackendEngineering #ExceptionHandling #APIDesign
To view or add a comment, sign in
-
-
REST API Design: More than just GET & POST Designing a good REST API is not about writing endpoints — it’s about designing contracts that scale, perform, and stay maintainable. This visual nicely summarizes what strong REST API design actually involves 👇 ✅ Core REST principles ✅ Stateless & cacheable communication ✅ Proper resource naming ✅ Pagination, filtering & ordering ✅ Versioning & monitoring ✅ Security, validation & rate limiting ✅ Idempotency & CORS ✅ Correct use of HTTP methods ✅ HATEOAS & self-descriptive messages As backend engineers, especially in Java / Spring Boot, we often focus on implementation — but design decisions made early decide long-term stability. 💡 A well-designed REST API: • scales better • is easier to consume • reduces breaking changes • improves developer experience • survives long-term product evolution If you’re building APIs for production systems, this checklist is worth revisiting again and again. 👇 Which REST principle do you think developers ignore the most? Comment your thoughts. #RESTAPI #BackendDevelopment #SystemDesign #Java #SpringBoot #Microservices #APIDesign #SoftwareEngineering #CleanCode #Developer
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