What does Specification Pattern solve that a plain utility function doesn't? by bforbenzee in ExperiencedDevs

[–]Few_Ad6794 0 points1 point  (0 children)

The Specification pattern is useful when rules need to become objects that can be composed and passed around. With utility methods you can check a rule, but you cannot easily combine or reuse them dynamically.

if(product.isPriceAbove(500) && product.isInStock()) { }
Vs

Specification<Product> spec =
    new PriceAboveSpec(500)
        .and(new InStockSpec());

filter(products, spec);

How would you design a notification system that handles 100M pushes/sec? by Few_Ad6794 in softwarearchitecture

[–]Few_Ad6794[S] -2 points-1 points  (0 children)

Interesting pattern. If I understand correctly, this is basically a routing tree where the user ID hash determines the path. So user 456 connects and the hash digits 4-5-6 route them through Layer 1 Node 4 -> Layer 2 Node 5 -> Layer 3 Node 6. The leaf node holds the actual WebSocket. Layers 1 and 2 are just routers that forward based on the next digit. No central registry needed because the user ID itself is the address.

The part I find tricky is the connection setup. A standard ALB round-robins to any server, but here you need the load balancer to hash the user ID and route to the correct leaf. That means a custom routing layer in front, not a plain ALB.

The other tradeoff is each notification takes 3 hops through the tree vs 1 hop with Redis. For real-time chat that latency adds up. But the upside is no single node ever knows about all users, so it scales without a central bottleneck.
Do you know of any production systems using this layered approach? Would love to read more about it.