56
votes

When using AWS AppSync with lambda data sources you can encounter N+1 query problem.

Basically when you have individual field resolver on your type and your query returns an array of those types you field resolver lambda will be called N times.

AWS introduces BatchInvoking lambdas in resolvers to combat this problem. Here you can read more about the problem and their solution: https://docs.aws.amazon.com/appsync/latest/devguide/tutorial-lambda-resolvers.html#advanced-use-case-batching

However, their solution is not working. BatchInvoking lambdas are limited to only 5 events (this is not stated in documentation). It is a slight improvement to the N+1 problem (it makes it N/5+1), but I think it is not enough as more complex queries tend to execute for a very long time and require more lambda invocations.

So my question is how do you deal with this problem? Is there any better solution to this?

I work on AWS AppSync team. I will be happy to pass this on as a feature request to customize the batch size for batch invoke. - Karthik
Half a year passed and there's no workaround yet. @Karthik, is it in the roadmap? - Nikola Petkanski
@ArthurGurov I think it is better to go with Apollo GraphQL for now, you can host apollo server on a conventional aws ec2 instance or even on aws lambda if you prefer - AlpacaGoesCrazy
Any update on this problem? It is a serious limitation - niqui
Just tested this again with a clean setup and this undocumented and unchangeable behaviour is still the case. You would expect AWS to at least document this behaviour after 3 years of not adding it, but no. - Bram