{"id":18649752,"url":"https://github.com/ashwanthkumar/structure_fi_coding_challenge","last_synced_at":"2025-11-05T10:30:30.663Z","repository":{"id":140451103,"uuid":"468425878","full_name":"ashwanthkumar/structure_fi_coding_challenge","owner":"ashwanthkumar","description":"Structure Financial Coding Challenge","archived":false,"fork":false,"pushed_at":"2022-03-20T16:02:41.000Z","size":151,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-27T12:44:47.646Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ashwanthkumar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-10T16:33:48.000Z","updated_at":"2022-03-10T17:26:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"8ec55d1a-9fc6-4baf-b4b5-55e7f4098b14","html_url":"https://github.com/ashwanthkumar/structure_fi_coding_challenge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanthkumar%2Fstructure_fi_coding_challenge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanthkumar%2Fstructure_fi_coding_challenge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanthkumar%2Fstructure_fi_coding_challenge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ashwanthkumar%2Fstructure_fi_coding_challenge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ashwanthkumar","download_url":"https://codeload.github.com/ashwanthkumar/structure_fi_coding_challenge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239456405,"owners_count":19641843,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T06:40:30.970Z","updated_at":"2025-11-05T10:30:30.593Z","avatar_url":"https://github.com/ashwanthkumar.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# structure_fi_coding_challenge\n\nSee [PROBLEM.md](PROBLEM.md) for the description of the problem statement.\n\n## Usage\nThis requires Go 1.17 toolchain to be installed on the machine.\n\n```\n$ make \u0026\u0026 ./structure_fi_coding_challenge\n```\n\nIn case you have docker and not have Go toolchain installed, you can also use Docker to build and run the project using the following commands\n\n```\n# Build the docker image\n$ docker build . -t structure_fi_by_ashwanth_kumar\n$ docker run -p 8080:8080 -it structure_fi_by_ashwanth_kumar\n```\n\nThis should start the application on port `8080` as default and we should be consuming the streams on the background.\n\nOnce the service starts, you can visit [http://localhost:8080/swagger/index.html](http://localhost:8080/swagger/index.html) for a swagger interface to test out the API implementation.\n\nI've also exposed an interface of `pprof` so we can visualize the profiling of the application while it is running. Once the server is started on `8080`, you can use the following tool to view the profile information on the browser:\n\n```\n$ go tool pprof -http=:8081 http://localhost:8080/debug/pprof/heap\n```\n\nThis should automatically open the browser to see the profile information.\n\n## Solution Notes\n\u003e First of all, thank you for the problem statement I had so much fun learning about t-digest and Perfect Hash Functions along the way.\n\nThe solution is written in Go and I've written tests pragmatically.\n\n### Median Calculation\nMedian calculation is backed by [t-digest](https://github.com/tdunning/t-digest/) data structure implementation. I'm using a [go](https://github.com/spenczar/tdigest) implementation in my solution. You can find on [store/store.go](store/store.go).\n\n### Hash Map\n\n\u003e If you follow through the commit history (see `3d12171`, `107122d`, `f344776`), you will notice that I got a working solution (a thin slice) using golang's in-built map data structure with a [Store abstraction](store/store.go) and then eventually replaced it with the custom hash map implementation. This is usually my development style, where I would like to focus on small slices of work and incrementally change / improve the design / code / performance as needed.\n\nCustom Hash Map implementation can be found at [store/custom_map.go](store/custom_map.go). I spent good time going through various [lectures](https://www.youtube.com/watch?v=0M_kIqhwbFo\u0026list=PLUl4u3cNGP61Oq3tWYp6V_F-5jb5L2iHb\u0026index=9), to find an general purpose hash function which will not have any collision and later stumbled upon a blog post that described about Minimal Perfect Hash Function against a known set of keys. Given our keys are the total list of symbols, we can indeed build a MPH using that list. I ended up using the implementation of [\"Hash, displace, and compress\"](http://cmph.sourceforge.net/papers/esa09.pdf) algorithm by the blog author at https://github.com/dgryski/go-mph. Now given a perfect hash function, I wrote a custom wrapper on top of this to store the values for each key in an array. The maximum memory requirement of this map is `O(n)` where `n` is the total number of symbols. Given the list is finite and known upfront I went with this solution.\n\nThank you for reading so far, irrespective of the outcome if you've any comments please do send them across.\n\n\n### Demo\n\n[![Structure.fi Backend Engineer Coding Challenge Demo](https://img.youtube.com/vi/KOoqQsezjRc/hqdefault.jpg)](https://www.youtube.com/watch?v=KOoqQsezjRc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwanthkumar%2Fstructure_fi_coding_challenge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fashwanthkumar%2Fstructure_fi_coding_challenge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fashwanthkumar%2Fstructure_fi_coding_challenge/lists"}