Table of Contents
Do not index
Do not index
This is my journey of building a Nostr relays service in the cloud
So, first of all, there are a lot of relays on the market. Why do I want to create a new one?
- I aim to create a new Java relay and a platform to create private/paid relays stored in the cloud (AWS).
- I intend to create my own to experiment with the Nostr protocol end to end. I have already started implementing a Nostr client, nostrsky.com, and a relay is what I need to understand the Nostr protocol end to end.
- Another reason is the fact that there are not so many Java implementations. People think that Java is old and not good for Nostr? But I believe that Java is keeping pace with the other languages.
- And there is another personal reason. I want to keep pace with modern Java. All these are fresh in 2023: Spring 6, SpringBoot 3, and Java JDK 20, Jakarta EE 10.
My inspiration for the technologies I want to use is in this presentation:
The Nostr relays on the market.
Here are some statistics about the existing Nostr relays:
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2F66fe5739-82bc-4d54-8d82-659983d62531%252Fdfdc01d5-8f59-4671-953c-4f6b4e701e96%252FScreenshot_2023-05-13_at_18.37.39.png&optimizer=image&quality=80&width=280)
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2F0ce1be93-b401-41f2-9dd2-ffb761580f45%252F33c3fd8e-9699-46a4-832c-ddbf7d7e040f%252FScreenshot_2023-05-13_at_18.37.58.png&optimizer=image&quality=80&width=280)
Here is a good description of the relay's relevance on the market:
What is a Nostr relay?
By definition, a relay stores Nostr events sent by clients and accept subscriptions from clients. Events are like this (in this case, we have an event of type 0 → meta-data):
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2Fc1417ade-0588-4fc4-83c9-2bd6a3d73987%252F8a01ff85-5fe7-46f8-8792-32da87789f4b%252FScreenshot_2023-05-15_at_22.55.33.png&optimizer=image&quality=80&width=280)
It can filter and offer search for events: profiles, notes, etc. Also can offer anti-spam support.
The relays can be paid at https://relay.exchange or not. A list of worldwide relays is here: https://nostr.watch/relays/find
Relays browsers:
Starting the project
I decided to use SpringBoot 3 (Spring Framework 6) and Java JDK 20 to build the relays service. See this URL: https://spring.io
Some reasons:
- support for Graal VM (native - improve startup time and lower usage of memory)
- ready for virtual threads (Loom project - improvements of runtime speed)
There is a very convenient way to start a project with Sprin Boot, but I can’t use it now:
- JHipster - https://www.jhipster.tech
- It has scaffolding for the UI
- but is not migrated to the new SpringBoot 3 / Spring 6
The lite version of JHipster is a good candidate because it already has the new Spring 6 / SpringBoot 3
- JHipster Lite - https://www.jhipster.tech/jhipster-lite
- clean architecture, incremental development
Playing with existing Java libraries for Nostr
So, I search the entire github.com, and I get just one Java library for working with Nostr protocol, and I don’t like it very much. Github: I https://github.com/tcheeric/nostr-java
- it uses lombock which has no future after Java introduced records (I used lombok in the past, but now it is obsolete)
- too much inheritance in the domain model (this is a sin of the academic world - in real projects, the composition is preferred)
- the way the project is structured, the maven sub-project is also not the best (it is better to be structured on NIPs)
- in-house JSON encoder/decoder is needed?
I started to browse fiatjaf repositories on github.com. Maybe I can find something better:
If not, I will use this library and try to create a better one afterward.
Bootstrapping the project
I initiated the project using Spring Initializr with some libraries: web sockets, persistence, and others.
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2Fdcaac558-a405-4e17-95e3-5a415041b213%252Fb09e6b87-48cd-4afe-b476-3e1658f630ee%252Fscreencapture-start-spring-io-2023-05-16-22_02_59.png&optimizer=image&quality=80&width=280)
I initialized a similar project but with JHipster Lite.
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2F38fc534e-9656-4647-bd63-1ac4558b6b33%252Fc7228dc3-4dbf-40ea-9ab9-96a616ec3cbd%252Fscreencapture-lite-jhipster-tech-landscape-2023-05-17-04_13_57.png&optimizer=image&quality=80&width=280)
I have to decide which of them to use to bootstrap my project!
A few days later….
I decided to use JHipster Lite because:
- it has already Spring Boot inside 🦾
- it has already UI (Angular) support
- extra utilities
But, I will use Clean Architecture and not Hexagonal Architecture. They are similar as the final goal, but I like Uncle Bob's approach more.
And see here the trends:
![notion image](https://cdn.feather.blog?src=https%3A%2F%2Fusenotioncms.com%2Fproxy%2Fblock%2Fc364b687-1ccc-4440-b5bd-fa86de9e3efe%252Fe762ca65-917e-4a03-aa22-f0f4b8323a73%252FScreenshot_2023-05-19_at_08.01.57.png&optimizer=image&quality=80&width=280)
I’m inspired by the following:
spring-shoestore
Github
spring-shoestore
Owner
spemberUpdated
Aug 30, 2023NEXT STEPS
- implement a first version of a relay server
- create a new feature in JHipster around the Nostr events (JHipster is generating just a dummy feature as a simple business example)
- save the events in different data sources: Postgres, Firebase, etc
- expose a relay on a web socket: https://docs.spring.io/spring-framework/reference/web/websocket/server.html
- play with Nostr Java: https://github.com/tcheeric/nostr-java
- test the relay with integration tests
- integrate the relay with an existing client
- publish the relay service in AWS
- create support for external users to create relays (public and private)