𝗧𝗼𝗽 𝟱 𝗥𝗮𝘁𝗲 𝗟𝗶𝗺𝗶𝘁𝗶𝗻𝗴 𝗔𝗹𝗴𝗼𝗿𝗶𝘁𝗵𝗺𝘀 𝗬𝗼𝘂 𝗦𝗵𝗼𝘂𝗹𝗱 𝗸𝗻𝗼𝘄: 1) 𝐓𝐨𝐤𝐞𝐧 𝐁𝐮𝐜𝐤𝐞𝐭 A bucket fills with tokens at a fixed rate. Each request consumes one token. If the bucket is empty (tokens run out) → request is throttled. Great when you want to allow short bursts while enforcing an average request rate. 2) 𝐅𝐢𝐱𝐞𝐝 𝐖𝐢𝐧𝐝𝐨𝐰 𝐂𝐨𝐮𝐧𝐭𝐞𝐫 Divides time into fixed windows (e.g., per minute). Counts requests in the current window. If the count exceeds the limit → block. Simple to implement, but suffers from burst spikes at window edges. 3) 𝐋𝐞𝐚𝐤𝐲 𝐁𝐮𝐜𝐤𝐞𝐭 Think of a queue that leaks at a constant rate. If new requests exceed queue capacity → they are dropped. Produces a smooth and predictable request flow. 4) 𝐒𝐥𝐢𝐝𝐢𝐧𝐠 𝐖𝐢𝐧𝐝𝐨𝐰 𝐋𝐨𝐠 Stores a timestamp for each request. For every new request, removes old timestamps outside the window and count the rest. Highly accurate, but expensive in memory for high-traffic systems. 5) 𝐒𝐥𝐢𝐝𝐢𝐧𝐠 𝐖𝐢𝐧𝐝𝐨𝐰 𝐂𝐨𝐮𝐧𝐭𝐞𝐫 Hybrid of Fixed Window + Log. Splits the window into smaller buckets and uses a weighted sum to estimate the rate. Provides good balance between accuracy and memory efficiency. Which of these do you use most often in production? ♻️ Repost to help more engineers learn this. #java #programming #software
More Relevant Posts
-
💡 𝗝𝗮𝘃𝗮/𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝐏𝐞𝐫𝐟𝐨𝐫𝐦𝐚𝐧𝐜𝐞 𝗧𝗶𝗽 🔥 💎 𝐉𝐚𝐯𝐚 𝟐𝟏 𝐕𝐢𝐫𝐭𝐮𝐚𝐥 𝐓𝐡𝐫𝐞𝐚𝐝𝐬 Managing thousands of concurrent operations? Platform threads choking your system? Here's the solution: 𝐕𝐢𝐫𝐭𝐮𝐚𝐥 𝐓𝐡𝐫𝐞𝐚𝐝𝐬! ✔This revolutionary feature from Project Loom provides super lightweight threads managed directly by the JVM. While classic threads consume MBs of memory, virtual threads stay at just KB level. 💡 𝐖𝐡𝐲 𝐚𝐫𝐞 𝐭𝐡𝐞𝐲 𝐠𝐚𝐦𝐞-𝐜𝐡𝐚𝐧𝐠𝐢𝐧𝐠? • Perfect for I/O-intensive operations. • Enable simple thread-per-request model at scale. • No need for complex reactive programming. • Backward compatible with existing code. ✨The magic happens when your application handles thousands of concurrent requests. ⚡Traditional threads would exhaust system resources, but virtual threads handle this elegantly. 🔥 They automatically yield when blocked, allowing other virtual threads to execute on the same platform thread. ✅ So, A REST API that previously handled 1000 concurrent connections can now handle 100,000+ with the same hardware, just by switching to virtual threads. 👍 𝐂𝐫𝐞𝐚𝐭𝐢𝐧𝐠 𝐭𝐡𝐞𝐦 𝐢𝐬 𝐬𝐢𝐦𝐩𝐥𝐞: Use Thread.ofVirtual() or Executors.newVirtualThreadPerTaskExecutor(). Your blocking code becomes scalable without rewriting! #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
💡 𝐉𝐚𝐯𝐚 𝟐𝟏 𝐏𝐞𝐫𝐟𝐨𝐫𝐦𝐚𝐧𝐜𝐞 𝐓𝐢𝐩 𝐕𝐢𝐫𝐭𝐮𝐚𝐥 𝐓𝐡𝐫𝐞𝐚𝐝𝐬 🔥 Managing thousands of concurrent operations? Platform threads choking your system? Here's the solution: Virtual Threads! 💎This revolutionary feature from Project Loom provides super lightweight threads managed directly by the JVM. While classic threads consume MBs of memory, virtual threads stay at just KB level. ✅ 𝐖𝐡𝐲 𝐚𝐫𝐞 𝐭𝐡𝐞𝐲 𝐠𝐚𝐦𝐞-𝐜𝐡𝐚𝐧𝐠𝐢𝐧𝐠? • Perfect for I/O-intensive operations. • Enable simple thread-per-request model at scale. • No need for complex reactive programming. • Backward compatible with existing code. ✨The magic happens when your application handles thousands of concurrent requests. ⚡Traditional threads would exhaust system resources, but virtual threads handle this elegantly. 🔥 They automatically yield when blocked, allowing other virtual threads to execute on the same platform thread. So, A REST API that previously handled 1000 concurrent connections can now handle 100,000+ with the same hardware, just by switching to virtual threads. 👍 𝐂𝐫𝐞𝐚𝐭𝐢𝐧𝐠 𝐭𝐡𝐞𝐦 𝐢𝐬 𝐬𝐢𝐦𝐩𝐥𝐞: Use Thread.ofVirtual() or Executors.newVirtualThreadPerTaskExecutor(). Your blocking code becomes scalable without rewriting! #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
C# 14 just made properties simpler, cleaner, and smarter with one new keyword: 𝐟𝐢𝐞𝐥𝐝. This release introduces the 𝐟𝐢𝐞𝐥𝐝 keyword, which lets you write property accessors without declaring a separate backing field. Instead of managing private variables manually, the compiler creates the backing field for you, and the 𝐟𝐢𝐞𝐥𝐝 token gives you direct access to it inside your getter or setter. This change streamlines common scenarios like adding validation, transforming input, or enforcing constraints. You keep full control of your logic while shedding repetitive boilerplate that clutters class definitions. Why this matters for developers: 1. Less boilerplate since explicit backing fields are no longer needed 2. Cleaner, more focused accessor syntax 3. Full flexibility to add logic in one or both accessors 4. Better readability and intent clarity 5. Fewer chances for typos or inconsistent naming ⚠️ If your type happens to already contain a member named 𝐟𝐢𝐞𝐥𝐝, you can still disambiguate with @𝐟𝐢𝐞𝐥𝐝 or 𝐭𝐡𝐢𝐬.𝐟𝐢𝐞𝐥𝐝, or rename the existing symbol for clarity. Small language enhancements like field keyword can make a big difference in maintainability and developer experience. Give it a try! Are you using the field keyword in your codebases? --- ♻️ Share this and help spread knowledge freely. 👉 Follow me [Elliot One] + Enable Notifications. #dotnet #csharp #programming #coding
To view or add a comment, sign in
-
-
🤔 It worked perfectly on my machine but suddenly broke in production 🤦♂️ That used to drive me crazy until I realized the root cause wasn’t the code itself, but the hidden assumptions it carried. One day, I was reviewing an issue where a background job kept failing randomly. The code looked fine, tests were green, logs were clean... until we realized something shocking: the job depended on the system’s time zone. On one server, UTC, on another, local time. Boom 💥 That’s when I learned one of the most underrated lessons in software engineering: Code doesn’t live in isolation, it lives in an environment. Here are a few silent killers I started paying close attention to: 🐍 Environment variables – never assume they exist everywhere. ⏰ DateTime handling – always clarify whether you’re using UTC or local time. 💾 File paths – don’t hardcode them; different OS means different structure. 🔐 Secrets – avoid embedding them in configs; use secure vaults instead. 💡 Dependencies – lock versions; "latest" can ruin your weekend. Since then, I’ve learned to ask: "What’s the environment like?" before I ask "What’s wrong with the code?" It’s amazing how many bugs vanish when you stop debugging your code and start debugging your assumptions. Don't let it stop here, repost and share ♻️ with your network to spread the knowledge ✅ #softwareengineering #programming #developers #csharp #dotnet #coding
To view or add a comment, sign in
-
-
4 attributes of scary code: 1. Feels needlessly complex. 2. Unclear intent. 3. No tests. 4. Buggy. 😬 This is a scary combo. It often means we're hesitant to touch it. Whoever does takes a big risk. Solution: 1. Create tests to cover the current working behavior. 2. Write a test that fails due to the buggy behavior. 3. Refactor to improve clarity, decomposing the code if necessary to improve the feedback loop and isolate the buggy section. 4. Make the test pass. How do you confront scary code in your projects? Drop your thoughts below! 👇 --- 👋 Join 28,000+ software engineers learning JavaScript, Software Design, and Architecture: https://thetshaped.dev/ ----- ♻ Repost to help others find it. #softwareengineering #programming #thetshapeddev
To view or add a comment, sign in
-
💡 𝗝𝗮𝘃𝗮/𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 𝗧𝗶𝗽 🔥 💎 𝗥𝗲𝘀𝘁𝗖𝗼𝗻𝘁𝗿𝗼𝗹𝗹𝗲𝗿 𝘃𝘀 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗘𝗻𝗱𝗽𝗼𝗶𝗻𝘁𝘀 ✅ 𝗥𝗲𝘀𝘁𝗖𝗼𝗻𝘁𝗿𝗼𝗹𝗹𝗲𝗿 have been the traditional way of building web APIs in Spring Boot. They provide a more organized and structured approach, especially for larger applications with multiple endpoints and complex routing. ✅ 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗘𝗻𝗱𝗽𝗼𝗶𝗻𝘁𝘀 were introduced in Spring 5 and aim to simplify the process of building reactive APIs with less ceremony. They are more concise and focus on functional programming style with RouterFunction and HandlerFunction. 💡 𝗪𝗵𝗲𝗻 𝘁𝗼 𝗨𝘀𝗲 𝗘𝗮𝗰𝗵 ◾ Use 𝗥𝗲𝘀𝘁𝗖𝗼𝗻𝘁𝗿𝗼𝗹𝗹𝗲𝗿 when you have a larger, more complex API with many endpoints and you need the structure and organization that controllers provide. ◾ Use 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗘𝗻𝗱𝗽𝗼𝗶𝗻𝘁𝘀 when you have a reactive application with WebFlux and want a more composable, functional approach. Functional endpoints are well-suited for microservices and reactive systems. 🔥 𝗛𝗼𝘄 𝘁𝗼 𝗖𝗼𝗻𝘃𝗲𝗿𝘁 𝗥𝗲𝘀𝘁𝗖𝗼𝗻𝘁𝗿𝗼𝗹𝗹𝗲𝗿 𝘁𝗼 𝗙𝘂𝗻𝗰𝘁𝗶𝗼𝗻𝗮𝗹 𝗘𝗻𝗱𝗽𝗼𝗶𝗻𝘁 ◾ 𝗗𝗿𝗼𝗽 𝗰𝗼𝗻𝘁𝗿𝗼𝗹𝗹𝗲𝗿𝘀: Use RouterFunction with route() builder instead. ◾ 𝗜𝗻𝗷𝗲𝗰𝘁 𝘀𝗲𝗿𝘃𝗶𝗰𝗲𝘀 𝗱𝗶𝗿𝗲𝗰𝘁𝗹𝘆: Pass them as @Bean parameters or use constructor injection. ◾ 𝗨𝘀𝗲 𝗦𝗲𝗿𝘃𝗲𝗿𝗥𝗲𝘀𝗽𝗼𝗻𝘀𝗲 𝗳𝗼𝗿 𝗿𝗲𝘀𝗽𝗼𝗻𝘀𝗲𝘀: Use ok(), created(), notFound() methods. ◾ 𝗟𝗼𝘀𝗲 𝘁𝗵𝗲 𝗮𝗻𝗻𝗼𝘁𝗮𝘁𝗶𝗼𝗻𝘀: Routing happens in the RouterFunction directly. #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
💡 𝗝𝗮𝘃𝗮/𝐒𝐩𝐫𝐢𝐧𝐠 𝐁𝐨𝐨𝐭 - 𝗦𝘁𝗿𝗲𝗮𝗺 𝗔𝗣𝗜 𝗧𝗶𝗽 🔥 💎 𝗮𝗻𝘆𝗠𝗮𝘁𝗰𝗵() 𝘃𝘀 𝗰𝗼𝗻𝘁𝗮𝗶𝗻𝘀(): 𝗪𝗵𝗶𝗰𝗵 𝗼𝗻𝗲 𝘁𝗼 𝘂𝘀𝗲? ✔ 𝗧𝗵𝗲 𝗣𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲 𝗗𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝗰𝗲 ArrayList.contains() is generally faster for simple existence checks because it avoids Stream creation overhead. However, Stream.anyMatch() offers flexibility with custom predicates and parallel processing capabilities. ⚡ 𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝗰𝗼𝗻𝘁𝗮𝗶𝗻𝘀()? ◾ Simple equality checks using equals(). ◾ Small to moderately large lists. ◾ Best performance for existence checks. ◾ Future-proof: switching to HashSet gives O(1) performance. 🎯 𝗪𝗵𝗲𝗻 𝘁𝗼 𝘂𝘀𝗲 𝗮𝗻𝘆𝗠𝗮𝘁𝗰𝗵()? ◾ Complex predicates or custom matching logic. ◾ Already working within Stream pipelines. ◾ Need parallel processing for very large datasets. ◾ Multiple field checks or partial matches. ✅ 𝗧𝗵𝗲 𝗕𝗼𝘁𝘁𝗼𝗺 𝗟𝗶𝗻𝗲 Use contains() for simple existence checks and best performance. Reserve anyMatch() for complex predicates or when working within Stream-based processing pipelines. #java #springboot #programming #softwareengineering #softwaredevelopment
To view or add a comment, sign in
-
-
The feeling you get when you’re asked a question in an interview that you’ve exactly dealt with. “How do you implement and handle Thread Safety in large Java applications?” Here’s a polished version of my answer When you’re running enterprise-grade systems, you’re not just handling logic , you’re handling concurrency. And in a multi-threaded world, even a tiny mistake in synchronization can snowball into production chaos. Let’s break it down: ✅ What causes thread safety issues? - Shared mutable state across threads (e.g., using static variables carelessly) - Improper synchronization in Singleton or utility classes - Non-thread-safe collections like ArrayList, HashMap used in parallel contexts - Race conditions when updating shared objects without locks or atomics ✅ What does it look like in production? - Inconsistent or corrupted data - Random failures that “disappear” on retries - CPU spikes due to lock contention - Strange bugs that you can’t reproduce locally ✅ How to fix it (and prevent it)? - Make shared objects immutable wherever possible - Use thread-safe alternatives like ConcurrentHashMap, CopyOnWriteArrayList, AtomicReference - Keep synchronization blocks short and precise - Avoid sharing mutable state across threads, pass data instead of sharing it - Rely on stateless design and dependency injection (Spring makes this much easier) - Always test under load and concurrency (tools like JMeter or Gatling help here) And above all, remember this rule of thumb: “If it’s shared and mutable, it’s probably dangerous.” Thread safety issues don’t shout at you in logs, they whisper through random failures. Get them right early, and you’ll save countless hours in debugging and rollback nightmares. #Java #SpringBoot #SoftwareEngineering #BackendDevelopment #JavaDevelopers #Microservices #Concurrency #ThreadSafety #EnterpriseSoftware #SystemDesign #CleanCode #PerformanceEngineering #Developers #CodingTips #TechCommunity #Programming #100DaysOfCode #TechLeadership
To view or add a comment, sign in
-
-
𝗖# 𝗧𝗿𝗶𝗰𝗸𝘀 𝗧𝗵𝗮𝘁 𝗦𝗮𝘃𝗲 𝗠𝗲 𝗛𝗼𝘂𝗿𝘀 𝗘𝘃𝗲𝗿𝘆 𝗪𝗲𝗲𝗸 Every developer has a few “go-to” shortcuts, small things that quietly make a big difference. Over the years, I’ve picked up a bunch of little C# tricks that save me time, reduce bugs, and make my code cleaner. Here are 10 of my favorites: 1️⃣ 𝘂𝘀𝗶𝗻𝗴 𝘃𝗮𝗿 𝗳𝗼𝗿 𝗮𝘂𝘁𝗼-𝗱𝗶𝘀𝗽𝗼𝘀𝗮𝗹 No need for extra braces or long using blocks, this one keeps your code compact and clean. 2️⃣ 𝗣𝗮𝘁𝘁𝗲𝗿𝗻 𝗺𝗮𝘁𝗰𝗵𝗶𝗻𝗴 It’s one of the most underrated C# features. Makes conditions way more readable: Example: if (obj is string s && s.Length > 0) Console.WriteLine(s); 3️⃣ 𝗻𝗮𝗺𝗲𝗼𝗳() 𝗳𝗼𝗿 𝗿𝗲𝗳-𝘀𝗮𝗳𝗲 𝘀𝘁𝗿𝗶𝗻𝗴𝘀 Instead of hardcoding property or method names, use nameof() it saves you from refactoring headaches later. 4️⃣ ?. 𝗮𝗻𝗱 ?? 𝗼𝗽𝗲𝗿𝗮𝘁𝗼𝗿𝘀 These two null helpers make code shorter and safer. Example: var length = user?.Name?.Length ?? 0; 5️⃣ 𝗟𝗜𝗡𝗤 .𝗔𝗻𝘆() 𝗶𝗻𝘀𝘁𝗲𝗮𝗱 𝗼𝗳 .𝗖𝗼𝘂𝗻𝘁() > 𝟬 It’s faster and clearer when all you want is to know if something exists. 6️⃣ 𝗦𝘁𝗿𝗶𝗻𝗴 𝗶𝗻𝘁𝗲𝗿𝗽𝗼𝗹𝗮𝘁𝗶𝗼𝗻 ($"") Way easier to read and maintain than concatenation. Example: Console.WriteLine($"User: {name}, Age: {age}"); 7️⃣ 𝘀𝘄𝗶𝘁𝗰𝗵 𝗲𝘅𝗽𝗿𝗲𝘀𝘀𝗶𝗼𝗻𝘀 They make mapping logic elegant and compact. var role = userType switch { 1 => "Admin", 2 => "Editor", _ => "Viewer" }; 8️⃣ 𝘃𝗮𝗿 𝗳𝗼𝗿 𝘁𝘆𝗽𝗲 𝗶𝗻𝗳𝗲𝗿𝗲𝗻𝗰𝗲 Use it wisely, keeps code concise without losing clarity. 9️⃣ 𝗿𝗲𝗰𝗼𝗿𝗱 𝘁𝘆𝗽𝗲𝘀 Perfect for immutable data objects. A single line replaces pages of boilerplate. 🔟 𝗦𝗽𝗮𝗻<𝗧> 𝗮𝗻𝗱 𝗠𝗲𝗺𝗼𝗿𝘆<𝗧> If you care about performance (especially in large data sets), these are game-changers. I keep finding new little gems like these that make development smoother. What’s one C# trick you’ve picked up that you can’t code without? #dotnet #csharp #codingtips #developerlife #softwareengineering #programming #devcommunity #dotnetcore
To view or add a comment, sign in
-
Ever wonder what happens to all those objects you new up in C#? The .NET runtime has a built-in janitor — the Garbage Collector (GC) — that tracks your memory, cleans up unused objects, and keeps your programs running smoothly. It's not a get out of jail free card though. You still need to handle unmanaged resources. Do you know what those are? Did you know the GC has 3 levels of "generations" for organizing its work or about the large object heap? In this post, I break down: * What garbage collection actually is * How generations, marking, and compaction work * Why .NET uses a managed heap * How memory leaks can still happen * And practical tips for writing GC-friendly code Full breakdown → https://lnkd.in/gtAiQ-xK #CSharp #DotNet #Programming #SoftwareEngineering #GarbageCollection #SyntacticSugarDaddy
To view or add a comment, sign in
More from this author
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