You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+26-10Lines changed: 26 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,26 +1,45 @@
1
1
# Developer Notes
2
2
3
-
run with docker-compose
3
+
## About the solution
4
4
5
-
docker-compose up --build
5
+
A few years ago I wrote a realtime chat scaling to infinite for a social TV startup which was based on Socket.io and used Layer 4 Load Balancing and Redis Pub/Sub to glue multiple Socket.io together. This worked very well in production and I would chose it again.
6
+
7
+
Since a Java backend was required for this task I decided to try something new:
8
+
I know Spring Boot and I heard about server side events (SSE) as a new way to push data via http to a web client. For persistence I chose MongoDB because it scales well and I needed a simple NO-SQL DB running in docker (I would tend to DynamoDB or similar in a cloud native environment). Looking into MongoDB I came across tailable cursors and a nice tutorial who to use them in Spring - https://www.baeldung.com/spring-data-mongodb-tailable-cursors - At this point the solution was clear and fired up my IDE. I struggled setting up a capped collection in mongodb which is needed for the tailable cursors - A stackexchange thread suggested to run a setup.js but I was not satisfied and found a way to do this in Java/ Spring at application startup and not triggered by docker-compose. I lost a fair bit of time at this point.
9
+
The solution works great and updates are almost instant. Any appended new message to the chat message collection is immediately sent to spring which is then doing the SSE magic and pushing it to the client. The client is already subscribed to the stream and appends the data to the list in the GUI. A normal POST endpoint is used to add a new chat row to the mongodb.
10
+
11
+
The frontend is coded in React which I love and use for a few years now. Having said this - I do React and Next.js but i don't do any CSS at all - I would be able to pick some tailwind components and add them to the Client to make it look nice but I ran out of time.
12
+
13
+
SSE seems to be supported through all current browsers https://caniuse.com/eventsource so one could also use this in production.
14
+
15
+
At the bottom of the this document I added a todo list of things I would have definitely realised if I had more time.
16
+
17
+
# Run the Demo
18
+
19
+
1. clone this repo from github
20
+
21
+
2. run with docker-compose in the root of the project
22
+
23
+
cd sse-chat/
24
+
docker-compose up --build
6
25
7
26
access the react frontend at
8
27
9
28
http://localhost:3000/
10
29
11
30
## TODO's
12
31
13
-
- Proper Input Validation on the react client side
32
+
- Proper input validation / sanitation on the react client side
14
33
- A LOT of error handling on the react side (EventSource onError - fetch errors etc, check HTTP status codes )
34
+
- check if SSE are supported in the browser (fallback to polling and add a none-reactive endpoint to retrieve Message list as json array)
15
35
- Monitoring of the springboot app (actuator)
16
36
- two stage build for spring docker image
17
-
- CSS!!! - i seriosly did run out of time - i would have grabbed a few nice tailwind components
18
37
- implement some proper test cases for the backendA API
19
38
- run tests as part of the build stage
20
-
- add send and recipient props on message
21
39
- add SECURITY - this chat is wide open
22
40
- add some nginx proxy in front of the react app and the backend app
23
41
- add swagger for the backend api
42
+
- CSS!!! - i seriosly did run out of time - i would have grabbed a few nice tailwind components
0 commit comments