β¨Dvurechenskyβ¨
AdPlatformService is a high-performance in-memory web service for storing and searching advertising platforms by location.
π Task documentation is also available in PDF: TASK.NET.pdf
π Test input file: test_input_data.txt
- β Table of Contents
dotnet run --project AdRegionServiceπ API: http://localhost:5411 π Swagger UI: http://localhost:5411/swagger
π API: http://localhost:5411 π Swagger UI: http://localhost:5411/swagger
Show API details
POST /api/load
Content-Type: multipart/form-data
[email protected]{
"message": "Data loaded",
"loaded": 123,
"skipped": 5
}GET /api/search?location=/ru/svrd[
{ "name": "Cool Ads", "locations": ["/ru/svrd"] },
{
"name": "Revdinsky Worker",
"locations": ["/ru/svrd/revda", "/ru/svrd/pervik"]
}
]-
π Load advertising platforms from file (
Stream) -
β‘ In-memory storage using immutable collections
-
π Load statistics (
loaded / skipped) -
π Hierarchical location search:
/loc1matches all platforms under this level/loc1/loc2also includes/loc1
-
π‘ Error handling:
OperationCanceledExceptionOutOfMemoryException- General errors are logged, state remains consistent
Method:
LoadFromStreamAsync(Stream stream, CancellationToken cancellationToken = default)-
β Accepts
Stream(supports files and network sources) -
β Ignores invalid lines:
- empty lines
- missing
: - empty platform name
- no valid locations
-
β Location indexing Stored in:
ImmutableDictionary<string, ImmutableHashSet<AdPlatform>>- β
Load statistics (
LoadStats) - β Progress logging every 100,000 lines
- β
Error resilience:
- keeps previous state on failure
- logs all exceptions
Yandex.Direct:/ru
Revdinsky Worker:/ru/svrd/revda,/ru/svrd/pervik
Ural Moscow Newspaper:/ru/msk,/ru/permobl,/ru/chelobl
Cool Ads:/ru/svrd- β
Method:
Search(string location) - β Uses indexed lookup (no full scan)
- β Supports hierarchical matching
- β
Returns
IEnumerable<AdPlatform> - β Thread-safe
- β‘ Efficient up to:
- 1β2 million entries
- 100β500 MB data
For >10M entries β consider external storage (PostgreSQL, full-text search, etc.)
ImmutableArrayImmutableDictionaryImmutableHashSet
β‘οΈ Thread-safe without locks
Search /a/b/c β checks:
/a/a/b/a/b/c
ILogger- Progress logging
- Error tracking
- Ready for integration (Seq, Kibana, etc.)
- Invalid data is skipped
- State is preserved on failure
- Search never throws exceptions
- Uses
HashSet<AdPlatform> - Removes duplicates automatically
- Returns lightweight enumerable
- β‘ High performance (1β2M entries)
- π‘ Robust error handling
- π Easy REST integration
- π§΅ Thread-safe architecture
-
xUnit tests
-
Covers:
- loading
- search
- edge cases
-
Run:
dotnet test- Docker build on push to
main - Publish to GitHub Container Registry
dotnet build+dotnet test
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem -subj "/CN=localhost"docker-compose up --builddocker pull ghcr.io/dvurechensky/net_junior_ads_test_task/adservice:latestdocker run -it --rm -p 5411:5411 ghcr.io/dvurechensky/net_junior_ads_test_task/adservice:latestβ¨Dvurechenskyβ¨
