Java

  • Làm sao tránh tạo trùng Order khi flash sale trong hệ thống e-commerce?
    Published on
    Trong bài viết này, mình sẽ cùng anh em tìm hiểu bài toán tạo trùng Order (duplicate order) trong một hệ thống e-commerce có rất nhiều người dùng truy cập đồng thời, đặc biệt là lúc flash sale. Mình đi từ nguyên nhân (user bấm đúp, refresh, client retry, message redelivery cho tới bot và replay attack), hậu quả khi đơn bị trùng, rồi lần lượt qua 6 cách xử lý từ cơ bản đến nâng cao - disable nút bấm, check-then-insert, Idempotency-Key với UNIQUE constraint, bảng idempotency record, Redis SET NX và checkout token dùng một lần - kèm code Java & Spring Boot cho từng cách và một bảng so sánh để anh em chọn đúng giải pháp.
  • Làm sao xử lý Inventory Reservation khi flash sale mà không bị oversell?
    Published on
    Trong bài viết này, mình sẽ cùng anh em tìm hiểu bài toán Inventory Reservation (giữ chỗ tồn kho) trong một hệ thống e-commerce có lượng truy cập đồng thời rất lớn, đặc biệt là lúc flash sale. Mình đi từ cách viết cơ bản nhất (đọc stock rồi trừ) và chỉ ra vì sao nó bị oversell, rồi lần lượt qua atomic UPDATE, pessimistic lock, optimistic lock, Redis Lua script và reservation có TTL, kèm code Java & Spring Boot cho từng cách và một bảng so sánh để anh em chọn đúng giải pháp cho hệ thống của mình.
  • RSQL: Làm sao để REST API “hiểu” các điều kiện FILTER một cách linh hoạt
  • Các bạn đã biết sự khác biệt giữa List.of() và Arrays.asList() trong Java chưa?
    Published on
    Trong Java có hai cách khởi tạo một list mà nhiều bạn vẫn hay sử dụng đó là Arrays.asList() và List.of(). Tuy nhiên, để hiểu và sử dụng đúng hai phương thức này thì có lẽ không phải ai cũng nắm được. Vì vậy, bài viết này mình sẽ cùng các bạn tìm hiểu kỹ hơn về hai phương pháp khởi tạo này.
  • Java Varargs: What is it and how it work?
    Published on
    Varargs were introduced in Java 5 and designed to solve the problem of handling an arbitrary number of parameters in a method. But what exactly is this problem? What are varargs and how can we use them effectively?
  • Simplify Resource Management With Try-With-Resources
    Published on
    Before Java 7, developers relied heavily on the traditional try-catch-finally approach to manage resources, which was often verbose and error-prone. With the introduction of try-with-resources, Java simplified this process significantly.
  • [Java] - How to write a custom Java annotation?
    Published on
    When working with the Java programming language, you're likely familiar with using annotations to mark methods or classes. But can we create our own custom annotations and use them in our code? The answer is yes! In this post, I’ll show you how to create a custom annotation for validating phone numbers.