RealEstate is an ASP.NET Core MVC web application with the following feature:
- get the top 10 real estate agents with the most properties.
Design considerations:
- In order to get the top 10 real estate agents, the
PropertyService
is making calls to the PartnerAPI. - Because the external API is returning a paginated response, all the pages have to be retrieved to be able to get the top 10 agents.
- In order to minimize the data stored in memory, every time a partial list is retrieved, the list of the top 10 is computed in place. That means that there won't be more than the size of the page agents stored in memory.
- Cache is used to improve performance.
- Retry pattern is used with Polly.
Further improvements:
- use Redis Cache and a worker roler to process the data and add it to the cache. The GET request will always hit the cache instead of performing expensive requests which take some time to be processed.
- deployment in Docker.
- run the AT against a mock API.
- Visual Studio 2019
- .NET Core 3.0.1 SDK
- .NET Core 3.0
- NUnit
- DTOs
- ASP.NET Core Web MVC
- Application contracts and implementation.
- Unit tests for all layers.
- Integration tests for getting the agents list.
Travis CI has been used to run the tests. Each pushed commit runs the unit tests.
- Replace in appsettings.json the
APIKey
and thePartnerAPI
base Url:
"PartnerAPI": {
"APIKey": "TBR"
},
"BaseUrls": {
"PartnerAPI": "TBR"
}
- Replace the
SalesObjectsPath
the Constants file:
/// <summary>
/// The path for objects which are on sale.
/// </summary>
public const string SaleObjectsPath = "TBR";
Polly is a library that provides resilience and transient-fault handling capabilities.
Polly has been used to define a Retry policy
for the HttpClient
:
services.AddHttpClient<ApiClient>(x =>
{
x.BaseAddress = new Uri(baseUrls.PartnerAPI);
})
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(10)
}));
Memory Cache has been used to improve perfomance. The cached item has a sliding expiration and an absolute expiration.
- Open solution in Visual Studio 2019
- Open Test Explorer
- Run the Order.UnitTests tests.
- Open solution in Visual Studio 2019
- Open Test Explorer
- Run the Order.IntegrationTests tests.
- Moq - mocking framewework used to mimic the behavior of classes and interfaces
- FluentAssertions