This project is a service that fetches the latitude and longitude of an object, along with its type and marketing type, and returns a list of similar objects with their prices.
To run the service locally, follow these steps:
- Start the Rails server.
- Start Sidekiq.
The project includes a Docker setup that contains the following services:
- Rails API
- PostgreSQL
- PostgreSQL Admin
- Redis
- Sidekiq
- Set environment variables for the database and Redis.
- Build the Docker image.
- Start the containers.
-
PostgreSQL Functions for Distance Calculation: PostgreSQL provides built-in functions to calculate distances efficiently. Refer to the PostgreSQL EarthDistance documentation for details.
-
Scalability: The service is designed to be easily scalable by running multiple Sidekiq workers and distributing database queries efficiently.
-
Response Time: The service is optimized to handle requests efficiently, with a response time of 400-320 ms for 1.75MB of data.
To improve performance and scalability, this project integrates Redis for caching. Redis helps optimize data fetching by storing data and reducing the number of redundant database queries. This leads to faster responses and a more scalable system.
Sidekiq is used to process background jobs asynchronously, improving scalability. For instance, tasks like fetching property details or calculating prices can be offloaded to background workers, allowing the main application to focus on handling incoming user requests.
Expensive or frequently accessed data can be cached to improve performance. By caching database queries with Redis, the service reduces the need to query the database repeatedly for the same data, which helps in improving response times and scalability.
The service uses geocoding functionality to fetch latitude and longitude for objects. To minimize external API calls and improve efficiency, geocoding results can be cached using Redis, ensuring that the same geocoding request does not need to be processed multiple times.
- Ensure that Sidekiq workers are running correctly to fetch and cache data efficiently.
- The Redis cache plays a key role in improving performance by reducing redundant database queries and enhancing response times.
- API responses are structured for quick access and efficient frontend usage.
For any issues or improvements, feel free to submit a pull request or open an issue!