Join Nostr
2025-09-30 00:44:26 UTC
in reply to

mccrmx on Nostr: I've been experimenting with relay selection and came up with this method for ...

I've been experimenting with relay selection and came up with this method for deterministically selecting an initial relay list for a given npub:

- Connect to some "bootstrap" popular relays.
- Query for random `kind=10002` and `kind=3` events.
- Build a big list of relays from the results (about 900 right now, takes 1 second).
- Hash every relay URL and the target/user's npub.
- Use Kademlia style XOR-distance to find the "closest" relays.
- Select the top 5 and use them.

This has the effect of distributing users over a large set of Nostr relays and reduces centralization pressure. Savvy users can always set their own relays, run their own relays etc. but I think this is better than hard coding "big" relays into apps. This algorithm has the additional benefit of being able to get a relay set for a participating user just by knowing their npub.

PoC: https://github.com/chr15m/nostr-dht