The system is designed for a food delivery platform, where the backend processes and transforms raw datasets into a structured format. This ensures intuitive navigation and efficient data access for front-end clients.
Golang (Go-chi, GORM) for backend development
MySQL for relational database design
Redis for caching
Elasticsearch for fast search
Jaegar for monitoring
Docker for containerized deployment
Postman for API testing
DB_USER="root"
DB_PASSWORD="password"
DB_HOST="db"
DB_PORT="3306"
DB_NAME="food_delivery"
PAGINATION_BATCH_SIZE="100"
REDIS_HOST="redis"
REDIS_PORT="6379"
ELASTICSEARCH_URL="http://elasticsearch:9200"
OTEL_EXPORTER_OTLP_ENDPOINT="jaeger:4317"
docker compose -f compose.yaml up
docker exec -it db /bin/sh -c "mysql --host localhost -u<user-name> -p<password> -e 'CREATE DATABASE IF NOT EXISTS food_delivery;'"
- Add Monitoring
- Host:
<yourhost>:8080 - Base Path:
/
POST /purchase
This endpoint allows a user to purchase a dish from a restaurant. It handles the potiential race condition and transaction atomically by:
- Deducting the user's balance.
- Updating the restaurant's balance.
- Recording the purchase history.
- Consumes:
application/json - Request Body:
{ "dish_id": 1, "user_id": 1 }
- 200: Purchase successful.
- 400: Invalid request.
- 500: Internal server error.
GET /restaurants/open
Retrieve a list of restaurants that are open at a specific date and time.
- Consumes:
application/json - Query Parameters:
datetime(string, required): Datetime in the formatYYYY-MM-DD HH:MM:SS.
- 200: A list of restaurants open at the specified datetime.
[ { "restaurant_name": "Restaurant A" } ] - 400: Missing or invalid
datetimeparameter. - 500: Internal server error.
GET /restaurants/top
Retrieve the top restaurants based on the number of dishes within a specified price range. Users can specify:
- Minimum and maximum price of dishes.
- Whether to get restaurants with more or fewer dishes than a certain count.
- The maximum number of restaurants to return.
- Consumes:
application/json - Query Parameters:
minPrice(number, required): Minimum price of dishes.maxPrice(number, required): Maximum price of dishes.minDishes(integer, required): Minimum or maximum number of dishes, depending onmoreOrLess.limit(integer, required): Maximum number of restaurants to return.moreOrLess(string, required): Condition for dish count ("more"or"less").
- 200: A list of top restaurants based on the number of dishes.
[ { "id": 1, "name": "Restaurant A", "dish_count": 10 } ] - 400: Invalid or missing query parameters.
- 500: Internal server error.
GET /search
Search for restaurants and dishes by name. The search term is matched against both restaurant and dish names.
- Consumes:
application/json - Query Parameters:
search(string, required): Search term.
- 200: A list of matching restaurants and dishes.
[ { "name": "Pizza", "type": "dish" }, { "name": "Italian Restaurant", "type": "restaurant" } ] - 400: Missing or invalid
searchparameter. - 500: Internal server error.
We have modified the dataset if necessary and doable. Based on modified dataset here are the database schema.
Jaegar for tracing.
http://localhost:16686