The Hive metastore (HMS) is a separate service, not part of Hive, not even necessarily on the same cluster. HMS stores the metadata on the backend for Hive, Impala, Spark, and other components.
Beeline, Hue, JDBC, and Impala shell clients make requests through thrift or JDBC to HiveServer. The redundant HiveServer is passive and provides fail-over services. The HiveServer instance reads/writes data to HMS. One or more HMS instances on the backend can talk to other services, such as Ranger. The redundant HMS is passive and provides fail-over services. The physical data resides in a backend RDBMS, one for HMS and one for the security service, Ranger for example. All connections are routed to a single RDBMS service at any given time. HMS talks to the NameNode over thrift and functions as a client to HDFS.