-
Notifications
You must be signed in to change notification settings - Fork 7
OptimistWeather project #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mrbelka12000
wants to merge
1
commit into
alem-platform:main
Choose a base branch
from
mrbelka12000:mrbelka12000/optimist_weather
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| ## Build | ||
| FROM golang:1.23.2-alpine3.19 AS buildenv | ||
|
|
||
| ADD go.mod go.sum / | ||
|
|
||
| RUN go mod download | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| ADD . . | ||
|
|
||
| RUN go build -o main cmd/main.go | ||
|
|
||
| ## Deploy | ||
| FROM alpine | ||
|
|
||
| WORKDIR / | ||
|
|
||
| COPY --from=buildenv /app/ / | ||
|
|
||
| EXPOSE 8081 | ||
|
|
||
| CMD ["/main"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| # **OptimistWeather** | ||
|
|
||
|
|
||
| ## Abstract | ||
|
|
||
| --- | ||
|
|
||
| This project focuses on optimizing weather query performance by leveraging **Redis** for caching and **PostgreSQL indexes** for | ||
| efficient database operations. It is designed for students to gain hands-on experience with query optimization techniques and database performance tuning using Go. | ||
|
|
||
|
|
||
| ## **Learning Objectives** | ||
|
|
||
| --- | ||
|
|
||
| - Understand the role of **Redis** in caching and reducing query load. | ||
| - Learn how to use **PostgreSQL indexes** to optimize query performance. | ||
| - Explore error handling and monitoring in Go applications. | ||
|
|
||
|
|
||
| ## **Context** | ||
|
|
||
| --- | ||
|
|
||
| ### Background | ||
| Weather APIs often experience performance bottlenecks due to frequent requests for real-time data. This project demonstrates how caching | ||
| and indexing can significantly improve query efficiency and scalability. | ||
|
|
||
| ### Real-World Applications | ||
| - Logistics and supply chain management | ||
| - Weather forecasting systems | ||
| - Disaster response platforms | ||
|
|
||
| ### Technical Concepts | ||
| - **Caching:** Store frequently accessed data temporarily for quick retrieval. | ||
| - **Indexes:** Enhance database query performance by reducing the search space. | ||
|
|
||
| ### Key Terms | ||
| - **Redis:** In-memory store used for caching and message brokering. | ||
| - **PostgreSQL Index:** A structure that accelerates data retrieval operations. | ||
|
|
||
|
|
||
| ## **Resources** | ||
|
|
||
| --- | ||
|
|
||
| - [Redis Documentation](https://redis.io/docs/) | ||
| - [PostgreSQL Indexing Guide](https://www.postgresql.org/docs/current/indexes.html) | ||
| - [Go Redis Client Library](https://github.com/go-redis/redis) | ||
| - [Cache strategies](https://medium.com/@mmoshikoo/cache-strategies-996e91c80303) | ||
|
|
||
|
|
||
|
|
||
| ## **General Criteria** | ||
|
|
||
| --- | ||
|
|
||
| - **Code Style:** Use `gofmt` for consistent formatting and adhere to Go idioms. | ||
| - **Compilation:** Ensure all code compiles cleanly using `go build`. | ||
| - **Execution:** Compatible with Linux or macOS systems; include Docker support. | ||
| - **Allowed Packages:** | ||
| - `github.com/go-redis/redis/v8` | ||
| - `github.com/lib/pq` | ||
| - **Disallowed Packages:** Frameworks that overly abstract caching or database operations. | ||
|
|
||
| ### Build Command: | ||
| ```bash | ||
| docker-compose up -d --build | ||
| ``` | ||
|
|
||
|
|
||
| ## **Mandatory Features** | ||
|
|
||
| --- | ||
|
|
||
| ### **Outcomes**: | ||
|
|
||
| - Reduce database query load by caching frequently accessed weather data. | ||
| - Functionality: Store and retrieve weather data in Redis with configurable TTL (Time-To-Live) / LRU / LFU. | ||
| - Optimize database queries by creating and using PostgreSQL indexes. | ||
| - Create indexes on relevant columns to improve query execution speed. | ||
|
|
||
|
|
||
| ### Notes: | ||
|
|
||
| --- | ||
|
|
||
| - Input: Location (e.g., city name or coordinates). | ||
| - Output: Weather data in JSON format. | ||
| - Handle invalid inputs gracefully and log errors. | ||
| - Ensure cache expiration for data freshness. | ||
|
|
||
|
|
||
| ## Constraints: | ||
|
|
||
| --- | ||
|
|
||
| - Handle errors gracefully and return appropriate HTTP status codes. | ||
| - All actions and errors must be logged. | ||
|
|
||
|
|
||
| ## Support Section | ||
|
|
||
| --- | ||
|
|
||
| - You can do it | ||
|
|
||
| ### Debugging Tips: | ||
| - Use redis-cli to monitor cache hits and misses. | ||
| - Run EXPLAIN/EXPLAIN ANALYZE in PostgreSQL to analyze query plans. | ||
| ```sql | ||
| EXPLAIN ANALYZE SELECT * FROM weather_data WHERE city = 'Astana'; | ||
| ``` | ||
|
|
||
|
|
||
| ### Common Issues and Fixes: | ||
|
|
||
| - Cache misses: Verify key structure and TTL configuration. | ||
| - Slow queries: Check if indexes are missing or misconfigured. | ||
|
|
||
|
|
||
| ### Where to Seek Help: | ||
| - Go forums and documentation | ||
| - Redis and PostgreSQL communities | ||
| - Stack Overflow for debugging Go applications | ||
|
|
||
|
|
||
|
|
||
| ## API Endpoints | ||
|
|
||
| --- | ||
|
|
||
| - TODO fill after | ||
|
|
||
| ## This project has been created by: | ||
|
|
||
| Beknur Karshyga | ||
|
|
||
| Contacts: | ||
| - Email: [karshyga.beknur@gmail.com](mailto:karshyga.beknur@gmail.com) | ||
| - GitHub: [mrbelka12000](https://github.com/mrbelka12000) | ||
| - LinkedIn: [Beknur Karshyga](https://www.linkedin.com/in/beknur-karshyga/) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| version: '2' | ||
| services: | ||
| redis__weather: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Тут специально 2 символна ниженего подчеркивания |
||
| image: redis | ||
| container_name: redis | ||
| ports: | ||
| - "6379:6379" | ||
| networks: | ||
| - optimist_weather | ||
| volumes: | ||
| - redis_data:/data | ||
|
|
||
| postgres_weather: | ||
| # TODO fill with weather data | ||
| image: postgres:latest | ||
| container_name: postgres_users | ||
| environment: | ||
| POSTGRES_USER: "postgres" | ||
| POSTGRES_PASSWORD: "mrbelka12000" | ||
| POSTGRES_DB: "optimist_weather" | ||
| DATABASE_HOST: "localhost" | ||
| ports: | ||
| - '5432:5432' | ||
| volumes: | ||
| - postgresData:/var/lib/postgresql/data | ||
| networks: | ||
| - optimist_weather | ||
|
|
||
| volumes: | ||
| redis_data: | ||
| postgresData: | ||
|
Comment on lines
+30
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Свести к consistency, чтобы названия ресурсов были либо в camelCase или snake_case |
||
|
|
||
| networks: | ||
| optimist_weather: | ||
| driver: bridge | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалить эти симолы, они не входят в шаблон