What's the benefit of GraphQL on Workers?

Interesting in getting some thoughts from the community on possibly using Cloudflare Workers and GraphQL for a greenfield project using microservices architecture.

Each microservice will run on a Cloudflare Worker and will need to query a MongoDB (fronted with a REST API), a number of external REST services, and possibly some Workers KV for non-critical data.

I considered using Apollo GraphQL Server to act as a common target for any microservice that wants to access the MongoDB or any external services. Effectively creating a “gateway API” which aggregates together all the other APIs together into one service making it easy to update and maintain.

But then I realised that if the Apollo GraphQL Server is running on Cloudflare Workers it won’t persist, meaning there is no benefit of query caching.

Also there would be an overhead of the microservice Worker making a connection to the GraphQL Worker, which then has to make a connection to the data source. Wouldn’t it be more performant for the microservice worker to just call the data source API directly?

The final concern is that I’m creating a single point of failure. While Cloudflare would scale the GraphQL Worker infinitely to handle load, if the config is bad then it would take down all API services for all microservices. If each microservice queried each datasource directly then that wouldn’t be an issue, albeit with slightly higher maintenance overhead.

So basically I’m struggling to see what benefit GraphQL on a Cloudflare Worker would offer for a microservice architecture. It seems like it’s better just for each microservice worker to query each datasource API directly.

Am I missing something? Are there any benefits of the Apollo GraphQL Server that I’m missing here?

Interested in your thoughts from the community. I’m sure some of you have been here before!

I’ve thought about it a lot and for my set of services I choose not to use GraphQL. I see more benefit with combining GraphQL when there’s front-end clients sending requests too it, rather than servers. Clients can always request the data they actually need, while on a server it’s more cemented what to retrieve/send. And yes, you’re right about the caching, there’s no central server so every request is unique, that’s one of the fundamental problems with serverless - which means, the target endpoint would get hammered and be vulnerable to internal DDOS.

1 Like