# Data exchange between workers

**URL:** <https://discuss.ray.io/t/data-exchange-between-workers/3055>\
**Category:** Ray Client\
**Created:** [July 28, 2021, 2:16pm UTC](https://discuss.ray.io/t/data-exchange-between-workers/3055 "2021-07-28T14:16:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phi32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/phi32/32/1161_2.png) [@phi32](https://discuss.ray.io/u/phi32)\
**Post date:** [July 28, 2021, 2:16pm UTC](https://discuss.ray.io/t/data-exchange-between-workers/3055/1 "2021-07-28T14:16:43Z")

</div>

Hi,

I need some advice on how I can structure data exchange between workers.  
My project has one task that creates lots of coordinates and a second task that evaluates a function (and does some other stuff) with the coordinate and returns the results to some owner that processes the results.  
The time both tasks take will vary over the execution of the program.  
I want to execute both tasks at the same time so that coordinates are produced, put in some place and whenever task two is free it can access a new coordinate to evaluate.  
What would be the best data structure to share data between the two tasks so they can work independently and in parallel? How do I make it accessible to both tasks?  
Is this possible with ray or do I have to use some other framework/library?

Thank you very much.

---

<div class="post-metadata">

**Author:** ![sangcho](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sangcho/32/425_2.png) [@sangcho](https://discuss.ray.io/u/sangcho)\
**Post date:** [July 28, 2021, 5:54pm UTC](https://discuss.ray.io/t/data-exchange-between-workers/3055/2 "2021-07-28T17:54:39Z")

</div>

Would you want this to be done in a streaming manner? or the evaluate will always be executed “after” producing a batch of coordinates is done?

---

<div class="post-metadata">

**Author:** ![phi32](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/phi32/32/1161_2.png) [@phi32](https://discuss.ray.io/u/phi32)\
**Post date:** [July 29, 2021, 6:20am UTC](https://discuss.ray.io/t/data-exchange-between-workers/3055/3 "2021-07-29T06:20:24Z")

</div>

Ideally, this would happen in an streaming manner, otherwise the waiting time for a batch might become very long.

---

<div class="post-metadata">

**Author:** ![ericl](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/ericl/32/133_2.png) [@ericl](https://discuss.ray.io/u/ericl)\
**Post date:** [August 3, 2021, 8:10pm UTC](https://discuss.ray.io/t/data-exchange-between-workers/3055/4 "2021-08-03T20:10:09Z")

</div>

Is this something datasets can implement? [Datasets: Distributed Arrow on Ray — Ray v2.0.0.dev0](https://docs.ray.io/en/master/data/dataset.html)

For example (not sure how coordinates are produced, but say we have a function to compute the ith coordinate `get_coord(i)`):

ds = ray.data.range(num\_coords)  
ds = ds.map(get\_coord)  
ds = ds.map(evaluate\_coord)

To perform this in a streaming manner, you can use the dataset pipelining feature:  
pipe = ray.data.range(num\_coords).pipeline(parallelism=10)  
pipe = pipe.map(get\_coord)  
pipe = pipe.map(evaluate\_coord)
