Twitter is simple Go API which sends the messages and query for messages containing a specific tag.
- Fiber - REST API framework, chosen beacuse of good performance benchmarks
- MongoDB - document database, perfect for this case
- Python/pytest - for integration/E2E tests
- Kubernetes - perfect to deploy and scale application
- Skaffold/Tilt - nice k8s development tools
POST /messages
Example: http://localhost:3000/messages
JSON Schema:
text- message to be postedtags- tags to be assigned to message
Sample JSON payload:
{
"text": "sample message",
"tags": ["tag1", "tag2"]
}
Sample response:
{
"count": 1,
"result": {
"id": "60c9f412a8b77a729096d3a5",
"text": "sample message",
"tags": [
"tag1",
"tag2"
],
"created_at": "2021-06-16T12:52:34.278183643Z"
},
"status": true
}
GET /messages
Example: http://localhost:3000/messages?from=2020-06-13T15:00:05Z&to=2021-06-13T15:00:05Z&tags=zx,zs
Query parameters:
tags- list of tags, comma separatedfrom- RFC3339-compatible start filtering timeto- RFC3339-compatible stop filtering time
Sample response:
{
"count": 1862,
"status": true
}
All needed dependencies and quickstart here.
skaffold dev- Use uploaded Postman collection (
Twitter.postman_collection.json) to call API
Prerequisites: use configuration from Configuration section.
-
Unit tests Type following commands to execute unit tests in Twitter development container:
make devmake test
-
Linting Folowing command installs necessary test dependencies and launches linters(golangci-lint, golint, goimports, gofmt) and checkers (gocyclo, go vet):
make devmake lint
-
E2E tests To launch E2E tests enter test Docker container (assumption: Twitter app, database and Test container are in the same network):
make dev- Enter development containermake build; ./twitter_app- in dev containermake dev-tests- to enter test containerpytest- to launch tests
-
Coverage report In order to generate coverage report, type following commands:
make dev- enter development containermake coverage- generate global coverage reportmake coverhtml- generate HTML coverage report
Both Twitter API and Test container are configured using environment variables(it's convenient to have .env file in main application directory):
API_PORT=3000
DB_URI=mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&appname=MongoDB%20Compass&ssl=false
DB_NAME=twitter
DB_COLLECTION_NAME=messages
Kubernetes is used to deploy solution:
- Build prod Docker image:
make build_image - Apply deployment yaml:
kubectl apply -f deployment/twitter-deployment.yaml - Check your minikube IP:
minikube ip - You can access Twitter API on minikube IP address, port
32000, likehttp://192.168.49.2:32000
- No authentication
- No performance tests (Python and locust could be used to measure that)
- No security tests
- No monitoring solution (ELK/Prometheus)
- No CI (private repository issues)
- No
api/v1used in endpoints - all in all, it's JSON API ;-) - No helm and other k8s improvements
- No automated API docs like Swagger