{"id":20517314,"url":"https://github.com/marialobillo/fcc-urlshortener","last_synced_at":"2026-05-05T04:04:50.550Z","repository":{"id":179517331,"uuid":"663615403","full_name":"marialobillo/fcc-urlshortener","owner":"marialobillo","description":"nodejs mongo redis ","archived":false,"fork":false,"pushed_at":"2023-07-27T10:47:57.000Z","size":136,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-06T20:47:30.528Z","etag":null,"topics":["api","freecodecamp-project","javascript","mongodb","nodejs","race-conditions","redis"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/marialobillo.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":"2023-07-07T17:56:48.000Z","updated_at":"2025-06-13T17:20:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"e78985ef-d999-476f-aad9-66488905da18","html_url":"https://github.com/marialobillo/fcc-urlshortener","commit_stats":null,"previous_names":["marialobillo/fcc-urlshortener"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marialobillo/fcc-urlshortener","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marialobillo%2Ffcc-urlshortener","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marialobillo%2Ffcc-urlshortener/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marialobillo%2Ffcc-urlshortener/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marialobillo%2Ffcc-urlshortener/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marialobillo","download_url":"https://codeload.github.com/marialobillo/fcc-urlshortener/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marialobillo%2Ffcc-urlshortener/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32634733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"online","status_checked_at":"2026-05-05T02:00:06.033Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api","freecodecamp-project","javascript","mongodb","nodejs","race-conditions","redis"],"created_at":"2024-11-15T21:34:52.716Z","updated_at":"2026-05-05T04:04:50.518Z","avatar_url":"https://github.com/marialobillo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# URL Shortener Microservice\n\nThis is the boilerplate code for the URL Shortener Microservice project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/back-end-development-and-apis/back-end-development-and-apis-projects/url-shortener-microservice.\n\n## Current Implementation Issues\n\n- We have not written any tests for our application. We could miss some cases and bugs.\n- I think we could have several simultaneous requests to our application. This could lead to a race condition.\n\n## Race Condition\n\nEven when Node.js is single-threaded we could have race condition on our project. This is because we are using a database to store our data. The database is not single-threaded. So, we could have several simultaneous requests to our application. This could lead to a race condition.\n\n## Solution 1 - Using Async/Await\n\nFirst potential solution is forcing the 'second' process to wait until the 'first' process has finished. We can do this using `async/await`.\n\n```javascript\n\nconst main = async () =\u003e {\n    await firstProcess();\n    await secondProcess();\n\n    ...\n}\n\n```\n\n## Solution 2 - Using Mutex\n\nAnother possible solution is using Mutex, which is a synchronization primitive that grants exclusive access to the shared resource to only one process at a time. This means that the second process will wait until the first process has finished.\n\n```javascript\n// https://www.nodejsdesignpatterns.com/blog/node-js-race-conditions/\n\nimport { Mutex } from 'async-mutex'\n\nconst mutex = new Mutex()\n\nasync function doingSomethingCritical() {\n  const release = await mutex.acquire()\n  try {\n    // ... do something here\n  } finally {\n    release()\n  }\n}\n\n```\n\n\n\nResources:\n- [Nodejs Race Conditions by Luciano Mammino](https://www.nodejsdesignpatterns.com/blog/node-js-race-conditions/)\n- [async-mutex](https://www.npmjs.com/package/async-mutex)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarialobillo%2Ffcc-urlshortener","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarialobillo%2Ffcc-urlshortener","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarialobillo%2Ffcc-urlshortener/lists"}