Clients-emails project.
Description.
Microservice that stores clients and send them emails based on mailing ID.
The service uses Go and PostgreSQL.
Both DB and app are containerized and can be run using docker-compose
.
Concerns
-
There are no test for every file because I found it pointless. One example test that covers every tested case is enough for presentation purposes.
-
Cursor - I've implemented simple cursor that bases on
where
andorder by
statements. It's simple and fast enough for that project. Along with index onid
column even with large amount of data I should be fast enough.If needed, we could use PostgreSQL builtin cursor functionality: cursor Also we could use other approach of API pagination like that: pagination.
-
Creating customer entries should be idempotent
- for simplicity I've usedUNIQUE INDEX
to ensure that. In more complex scenario I'd consider using locks on db because with multiple instance of that app we could encounter problems.
Local setup
Make sure that you have go installed.
- Install dependencies.
go mod download & go mod vendor
- Crate DB if not exists.
docker run --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=postgres POSTGRES_DB=vodeno POSTGRES_USER=postgres -d postgres:14
- Run an app.
go run cmd/main.go
- Or use docker-compose setup. It will build docker image of an app and pull postgres image. App will run on
8080
port.
docker-compose up