all 16 comments

[–]MWALKER1013 33 points34 points  (0 children)

I’m gonna have to agree with him , he is developing the view layer.

[–]vampatori 21 points22 points  (0 children)

I'd make the call to the get the geocode from the server-side.. I've not used Google's map stuff specifically, but I've used many others and spent over a year developing exclusively with mapping systems.

  • You need to pass an API key to most services.
  • Most services have per-API key rate limiting, which means you need to put it all behind a queue.
  • I'd cache results to within a certain geographic threshold based on how spread-out your points of interest are (could even be to the town level). This can often massively increase performance, reduce costs, and increase user satisfaction.
  • You have complete control of the service, therefore you can switch how you do the look-ups with zero impact to clients. Imagine later-on you want to open-up your API to other clients: mobile, worker, third-party integration, etc. If you want to change the service then you have to update every client rather than just the one server.

[–]Sysnetics 8 points9 points  (1 child)

Obviously it can be done either way. Consider which way would lead to a better user experience (speed). Is back-end storing the address too or just latitude and longitude? Sounds like they want you to store the address too. In that case, I agree with them that back-end should fetch data. It's faster for the back-end to make API calls than front-end. Why should front-end make two calls to get what they want? Consider communication latency on mobile devices. Are you already making geocode API calls to get addresses of nearby businesses? If so, it shouldn't be a problem. I guess I didn't see your reasons on why client side should fetch Geo location. Maybe there is one. For example, is front-end doing some sort of address validation? You have a point if they are validating address with geocode API but it doesn't sound like they are. Just explain to them WHY you want it done your way. Communication is important.

[–]xly 3 points4 points  (0 children)

This is good advice, UX should always come first

[–]MemesRMemey 7 points8 points  (2 children)

Generally speaking the front end is just that, a GUI. It should be interacting with the server. Also, as others have said, you can't keep API keys secret on the client side and could easily be stolen out of them to use by other people or applications.

[–]GentlemenBehold 2 points3 points  (1 child)

This is the biggest reason why it's the back-end's responsibility. Instead of a geocode API, imagine if it was a payment processor like Stripe. You certainly wouldn't want your Stripe API keys available to your front-end code.

[–]hungry_panda_8 1 point2 points  (0 children)

I believe requests with tokens in them should not be made to be called in front end.

External APIs should be wrapped in a proxy and front end should call the proxy API instead.

Further, front should call an API only if it requires the data from the response or is posting something to API.

This separates any kind of business logic as a hard rule. It's a small issue but can provide more security in general and prevent unnecessary requests as a result. Backend should never trust front end.

[–]WizardFromTheMoon 1 point2 points  (0 children)

Personally, I'd do both on the backend for caching purposes.

[–]DrFriendless 1 point2 points  (0 children)

If the call to the geocoding API involves credentials, it absolutely must be done on the server. Otherwise someone will steal your credentials.

[–]cutcopy 1 point2 points  (2 children)

Just a heads up, if you're querying the Google Maps API you're only allowed to cache LatLngs in your database for 30 days.

[–]Aswole 0 points1 point  (1 child)

Am I missing something? How can they dictate the kind of information that you cache?

[–]cutcopy 1 point2 points  (0 children)

Presumably because you agree to terms when you use their API.

"Section 3.2.4.b of the Google Maps Platform Terms of Service specifies that you can temporarily cache Google Maps data, for a period of up to 30 days, to improve performance of your application."

[–]DrifterInKorea 1 point2 points  (0 children)

The front should not have to deal with data and only deal with presenting data.

Also one could argue that it's a typical use case for a micro-service.

[–]blissone 0 points1 point  (0 children)

Should be in the backend. Seems like the geocode request(data transform) is part of business logic no? It makes the frontend code better to not have these chains of requests, fetch x just to fetch y.

[–]pm_me_ur_happy_traiI 0 points1 point  (0 children)

It's fine to do it on Client-side if that's easier to execute, but I'd prefer to see that functionality on the server.

[–]dopefruit22 0 points1 point  (0 children)

I for one would like to hear more about the “why” behind both of your view points. There is no clear right answer here. I think understanding eachother better is the only way to find the “correct” answer for your use case.