# Object sharing between separate clients

**URL:** <https://discuss.ray.io/t/object-sharing-between-separate-clients/979>\
**Category:** Ray Core\
**Created:** [February 22, 2021, 9:12pm UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979 "2021-02-22T21:12:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrrobby](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mrrobby/32/517_2.png) [@mrrobby](https://discuss.ray.io/u/mrrobby)\
**Post date:** [February 22, 2021, 9:12pm UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979/1 "2021-02-22T21:12:00Z")

</div>

Hello! If two clients are running as separate processes and one puts  
data into the object store, is there a way to use the `ObjectRef`  
from one to access the objects in the store from the other?

#### Libs

```python
@ray.remote
def serialize(value):
   c = ray.put(value)
   print('returned value is %s' % c)
   return c

@ray.remote
def deserialize(value):
   print('value 1234 is %s' % value)
   print('type value is %s' % type(value))
   return ray.get(value)

```

#### Process A

```python
ray.util.connect('127.0.0.1:10001')
data_string = '{"1001": 301.27, "1002": 433.21, "1003": 502.22}'
order_data_dict = json.loads(data_string)
ret_ref = serialize.remote(order_data_dict)
(pid=xyz) returned value is ObjectRef(some_id)

```

> Inside the serialize function ray.put returns ObjectRef(some\_id)  
> but the returned value is

```python
ref_ref
ClientObjectRef(some_other_id)

```

Then pickling to send across processes

```python
ret_p = pickle.dumps(ret_ref)

```

#### Process B

`ret_p` is passed to the process

```python
ray.util.connect('127.0.0.1:10001')
result = pickle.loads(ret_p)
val = deserialize.remote(result) #Fails

```

expected would hope to be

```python
ray.get(val)
{'1001': 301.27, '1002': 433.21, '1003': 502.22}

```

It seems the `ClientObjectRef` is specific to the client, but  
is there a way to get the actual object ref so multiple clients  
can access the object in the store? Or is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [February 22, 2021, 9:34pm UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979/2 "2021-02-22T21:34:09Z")

</div>

Hey @mrrobby ! What if you try using a [named actor](https://docs.ray.io/en/master/actors.html#named-actors) to act as a key value store?

---

<div class="post-metadata">

**Author:** ![mrrobby](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mrrobby/32/517_2.png) [@mrrobby](https://discuss.ray.io/u/mrrobby)\
**Post date:** [February 23, 2021, 7:48pm UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979/3 "2021-02-23T19:48:11Z")

</div>

Thanks @rliaw! I did something like this and it seems to work:

```python
@ray.remote
class RayStore(object):
    def get(self):
       return self.value

    def put(self, value):
        self.value = value

```

If there are lots of processes accessing an object set this way, could there be some extra overhead that could result, or conversely, could this save from unnecessary copies of objects from being made?

---

<div class="post-metadata">

**Author:** ![rliaw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/rliaw/32/24_2.png) [@rliaw](https://discuss.ray.io/u/rliaw)\
**Post date:** [February 24, 2021, 12:41am UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979/4 "2021-02-24T00:41:06Z")

</div>

> [@mrrobby](#):
>
> If there are lots of processes accessing an object set this way, could there be some extra overhead that could result, or conversely, could this save from unnecessary copies of objects from being made?

Hmm, maybe you could do a `v = ray.put(self.value); return v` inside `def get(self)`. That would allow the object ref to be cached/re-used.

---

<div class="post-metadata">

**Author:** ![mrrobby](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/mrrobby/32/517_2.png) [@mrrobby](https://discuss.ray.io/u/mrrobby)\
**Post date:** [February 24, 2021, 10:14pm UTC](https://discuss.ray.io/t/object-sharing-between-separate-clients/979/5 "2021-02-24T22:14:57Z")

</div>

This seems to work. I’ll try this for some of the starting stuff and then we can profile as we move through to see what’s happening. Thank you!
