简体   繁体   English

建议通过 Google Places 自动完成 API 创建代理 API

[英]Suggestion to create a proxy API over Google Places autocomplete API

I am a mobile developer and have started using Google Place API for an autocomplete suggestion to find places in my app.我是一名移动开发人员,并已开始使用 Google Place API 提供自动完成建议,以便在我的应用中查找地点。 But I have observed that Google Places API becomes costly when scaling.但我观察到 Google Places API 在扩展时成本很高。 So i have made some optimization on the mobile side as follows:-所以我在移动端做了一些优化如下:-

  1. Limit autocomplete for at least 3 character限制自动完成至少 3 个字符
  2. The threshold value to make API call for autocomplete is the 500millisecond difference between 2 characters typed使 API 调用自动完成的阈值是键入的 2 个字符之间的 500 毫秒差异
  3. Do a local caching of results with LRU mechanism使用 LRU 机制对结果进行本地缓存

With all this optimization client side is good.有了所有这些优化,客户端就很好了。 But now I am also thinking to optimize from backend API side also.但现在我也在考虑从后端 API 方面进行优化。 For this optimization, I will create a wrapper for google places auto-complete api with server-side caching.对于此优化,我将为带有服务器端缓存的 google 位置自动完成 api 创建一个包装器。 This caching will have a time-span of 30days as per Google Guidelines.根据 Google 指南,此缓存的时间跨度为 30 天。

I need help to understand how can i design this?我需要帮助来理解我如何设计这个? Like what key and value combination i need to store autocomplete suggestion?就像我需要存储自动完成建议的键和值组合一样? Should I use Redis or Hazelcast?我应该使用 Redis 还是 Hazelcast? I am writing my Backend in Java with aws server using micro-service architecture.我正在使用微服务架构使用 aws 服务器用 Java 编写后端。 Any already implemented solution where I can look into and learn.任何已经实施的解决方案,我可以研究和学习。

Please help as I am a newbie Backend developer.请帮助,因为我是新手后端开发人员。

Before going down this path, have you done a cost analysis to see if this will be worthwhile?在走这条路之前,您是否进行了成本分析,看看这是否值得? Keep in mind, this is now code that you need to maintain, and cloud infrastructure does require some care and feeding.请记住,这是您现在需要维护的代码,云基础架构确实需要一些照顾和喂养。 ie in your pricing analysis, don't forget to factor in your time to the cost calculations.即在您的定价分析中,不要忘记在成本计算中考虑您的时间。 Is it still financially worth it?它在经济上仍然值得吗?

Not knowing your transaction volumes, it sounds like you've done a fair amount of free optimization on the client side.不知道您的交易量,听起来您已经在客户端做了大量的免费优化。 If you add the server-side optimizations, you're effectively adding a cloud-to-cloud call, and the extra latency of the various AWS services you're using.如果您添加服务器端优化,您实际上是在添加云到云调用,以及您使用的各种 AWS 服务的额外延迟。 Are you ok, taking a performance hit?你还好吗,表现不佳?

If you still think it's worthwhile, the path I would recommend is to go the serverless route using API Gateway -> Lambda -> DynamoDB.如果您仍然认为值得,我推荐的路径是使用 API Gateway -> Lambda -> DynamoDB 的无服务器路线。 This will keep your costs relatively low since Lambda has a fairly generous free tier.这将使您的成本相对较低,因为 Lambda 有一个相当慷慨的免费套餐。 If you need faster performance, you can always insert Redis via Elasticache into the stack later.如果您需要更快的性能,您可以随时通过 Elasticache 将 Redis 插入堆栈。

As far as what you need to store, you'd probably want to cache the various inputs the user is entering along with the information returned from the places API.至于您需要存储的内容,您可能希望缓存用户输入的各种输入以及从地点 API 返回的信息。 For example, you'll probably want to capture search string, location information, and then any of the fields you want (eg place_id, icon, opening_hours, etc.);例如,您可能想要捕获搜索字符串、位置信息,然后是您想要的任何字段(例如 place_id、icon、opening_hours 等); basically whatever you're using today.基本上无论你今天使用什么。 It would have very similar needs to your LRU cache.它与您的 LRU 缓存有非常相似的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM