1

I am using ASP.NET MVC 4 for my website actually. This website will share the same database than my game database (logins and user profiles). I will be using the WebAPI only for game logic and requests so there definitivly going to have high traffic there. I only serve 2 methods one for the authentification and one for the requests. (There a kind of huge architecture behind which i won't explain here). Since ASP.NET MVC 4 can integrate rather easily the web.api by adding almost nothing i though myself.. why not adding the api directly to my website project to avoid code duplication. Do you think this is a good choice and why ?

Thanks!

j0k
  • 22,600
  • 28
  • 79
  • 90
Rushino
  • 9,415
  • 16
  • 53
  • 93

1 Answers1

1

Your question seems to be more of how should I scale-out and less about should I use Web API in same project as my website. Not knowing the details it is difficult to recommend how you should scale out, so I'll stick with answering your original query about including the Web API in same Web Site or not.

Assuming that that the game and game logic (Web Api) you are intending to be a part of your website e.g. www.mysuperniftygame.com (or whatever your URL is), then yes you probably want the Web API to be part of the web site. Why? That way you won't be needing a sub-domain for your API requests e.g. gameapi.mysuperniftygame.com.

Why is that important? Well, if your web site and web app are making API requests you likely don't won't to have to deal with cross domain issues where you'd have to incorporate things like JSONP or CORS just to make requests to your own Web API.

As for scale-out and the API being a high amount of traffic, you can scale out the web front end(s) horizontally AND you should consider at least the following two things:

  1. Make the controller (API controllers in this case) lean by having the code implemented outside of the controller which is best practice
  2. Make the API controllers execute asynchronously which should help your web site and API continue to be responsive even if there is a long running request to your DB.
Community
  • 1
  • 1
Daron Cox
  • 171
  • 1
  • 5